2016-12-08 23:14:26 +00:00
unit mbColorPalette;
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
interface
{$I mxs.inc}
uses
{$IFDEF FPC}
LCLIntf, LCLType, LMessages,
{$ELSE}
Windows, Messages,
{$ENDIF}
SysUtils, Classes, Controls, Graphics, {$IFDEF DELPHI_7_UP} Themes, {$ENDIF}
2016-12-09 23:47:46 +00:00
Forms, HTMLColors, PalUtils, Dialogs, mbBasicPicker;
2016-12-08 23:14:26 +00:00
type
TMouseLoc = ( mlNone, mlOver, mlDown) ;
TTransparentStyle = ( tsPhotoshop, tsPhotoshop2, tsCorel, tsMicroangelo, tsNone) ;
TCellStyle = ( csDefault, csCorel) ;
TColorCellState = ( ccsNone, ccsOver, ccsDown, ccsChecked, ccsCheckedHover) ;
TMoveDirection = ( mdLeft, mdRight, mdUp, mdDown) ;
TPaintCellEvent = procedure ( ACanvas: TCanvas; ACellRect: TRect; AColor: TColor; Index : integer ; AState: TColorCellState; var AStyle: TTransparentStyle; var PaintingHandled: boolean ) of object ;
TCellClickEvent = procedure ( Button: TMouseButton; Shift: TShiftState; Index : integer ; AColor: TColor; var DontCheck: boolean ) of object ;
TGetHintTextEvent = procedure ( AColor: TColor; Index : integer ; var HintStr: string ; var Handled: boolean ) of object ;
TArrowKeyEvent = procedure ( Key: Word ; Shift: TShiftState) of object ;
2016-12-09 23:47:46 +00:00
TmbColorPalette = class( TmbBasicPicker)
2016-12-08 23:14:26 +00:00
private
FMouseLoc: TMouseLoc;
FMouseOver, FMouseDown, FAutoHeight: boolean ;
FColCount, FRowCount, FTop, FLeft, FIndex, FCheckedIndex, FCellSize, FTotalCells: integer ;
2016-12-15 09:05:53 +00:00
//PBack: TBitmap;
2016-12-08 23:14:26 +00:00
FState: TColorCellState;
FColors, FNames: TStrings;
FPalette: TFileName;
FHintFormat: string ;
FOnChange, FOnColorsChange: TNotifyEvent;
FMinColors, FMaxColors: integer ;
FSort: TSortMode;
FOrder: TSortOrder;
FOld: TColor;
FOnPaintCell: TPaintCellEvent;
FTStyle: TTransparentStyle;
FOnCellClick: TCellClickEvent;
FOldIndex: integer ;
FOnGetHintText: TGetHintTextEvent;
FCellStyle: TCellStyle;
FOnArrowKey: TArrowKeyEvent;
function GetMoveCellIndex( move: TMoveDirection) : integer ;
function GetSelColor: TColor;
procedure SetCellStyle( s: TCellStyle) ;
procedure SetTStyle( s: TTransparentStyle) ;
procedure SetCellSize( s: integer ) ;
procedure SetSortMode( s: TSortMode) ;
procedure SetSortOrder( s: TSortOrder) ;
procedure SetMinColors( m: integer ) ;
procedure SetMaxColors( m: integer ) ;
procedure SetAutoHeight( auto: boolean ) ;
procedure LoadPalette( FileName: TFileName) ;
procedure SetStrings( s: TStrings) ;
procedure SetNames( n: TStrings) ;
procedure SetSelColor( k: TColor) ;
procedure SortColors;
procedure CalcAutoHeight;
function GetTotalRowCount: integer ;
protected
procedure Paint; override ;
procedure PaintTransparentGlyph( ACanvas: TCanvas; R: TRect) ;
2016-12-16 14:22:33 +00:00
procedure DrawCell( ACanvas: TCanvas; AColor: string ) ;
2016-12-08 23:14:26 +00:00
procedure DrawCellBack( ACanvas: TCanvas; R: TRect; AIndex: integer ) ;
procedure ColorsChange( Sender: TObject) ;
procedure Click; override ;
procedure Resize; override ;
procedure SelectCell( i: integer ) ;
2016-12-16 14:22:33 +00:00
// procedure CreateWnd; override;
2016-12-08 23:14:26 +00:00
procedure MouseDown( Button: TMouseButton; Shift: TShiftState; X, Y: Integer ) ; override ;
procedure MouseUp( Button: TMouseButton; Shift: TShiftState; X, Y: Integer ) ; override ;
procedure MouseMove( Shift: TShiftState; X, Y: Integer ) ; override ;
{$IFDEF DELPHI}
procedure CMMouseEnter( var Message : TMessage) ; message CM_MOUSEENTER;
procedure CMMouseLeave( var Message : TMessage) ; message CM_MOUSELEAVE;
procedure CNKeyDown( var Message : TWMKeyDown) ; message CN_KEYDOWN;
procedure CMGotFocus( var Message : TCMGotFocus) ; message CM_ENTER;
procedure CMLostFocus( var Message : TCMLostFocus) ; message CM_EXIT;
procedure CMEnabledChanged( var Message : TMessage) ; message CM_ENABLEDCHANGED;
procedure CMHintShow( var Message : TMessage) ; message CM_HINTSHOW;
{$ELSE}
procedure CMMouseEnter( var Message : TLMessage) ; message CM_MOUSEENTER;
procedure CMMouseLeave( var Message : TLMessage) ; message CM_MOUSELEAVE;
procedure CNKeyDown( var Message : TLMKeyDown) ; message CN_KEYDOWN;
procedure CMGotFocus( var Message : TLMessage) ; message CM_ENTER;
procedure CMLostFocus( var Message : TLMessage) ; message CM_EXIT;
procedure CMEnabledChanged( var Message : TLMessage) ; message CM_ENABLEDCHANGED;
procedure CMHintShow( var Message : TLMessage) ; message CM_HINTSHOW;
{$ENDIF}
2016-12-09 23:47:46 +00:00
2016-12-08 23:14:26 +00:00
public
constructor Create( AOwner: TComponent) ; override ;
destructor Destroy; override ;
function GetColorUnderCursor: TColor;
function GetSelectedCellRect: TRect;
function GetIndexUnderCursor: integer ;
property ColorUnderCursor: TColor read GetColorUnderCursor;
property VisibleRowCount: integer read FRowCount;
property RowCount: integer read GetTotalRowCount;
property ColCount: integer read FColCount;
property IndexUnderCursor: integer read GetIndexUnderCursor;
procedure SaveColorsAsPalette( FileName: TFileName) ;
procedure GeneratePalette( BaseColor: TColor) ;
procedure GenerateGradientPalette( Colors: array of TColor) ;
2016-12-09 23:47:46 +00:00
2016-12-08 23:14:26 +00:00
published
property Align;
property Anchors;
property Enabled;
property SortMode: TSortMode read FSort write SetSortMode default smNone;
property SortOrder: TSortOrder read FOrder write SetSortOrder default soAscending;
property MinColors: integer read FMinColors write SetMinColors default 0 ;
property MaxColors: integer read FMaxColors write SetMaxColors default 0 ;
property SelectedCell: integer read FCheckedIndex write SelectCell default - 1 ;
property SelectedColor: TColor read GetSelColor write SetSelColor default clNone;
property Colors: TStrings read FColors write SetStrings;
property Palette: TFileName read FPalette write LoadPalette;
property HintFormat: string read FHintFormat write FHintFormat;
property AutoHeight: boolean read FAutoHeight write SetAutoHeight default false ;
property CellSize: integer read FCellSize write SetCellSize default 1 8 ;
property TransparentStyle: TTransparentStyle read FTStyle write SetTStyle default tsNone;
property CellStyle: TCellStyle read FCellStyle write SetCellStyle default csDefault;
property ColorNames: TStrings read FNames write SetNames;
{$IFDEF DELPHI_7_UP} {$IFDEF DELPHI}
property ParentBackground default true ;
{$ENDIF} {$ENDIF}
property TabStop default true ;
property TabOrder;
property ShowHint default false ;
property Constraints;
property ParentShowHint default true ;
property PopupMenu;
property Visible;
property DragCursor;
property DragKind;
property DragMode;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnStartDock;
property OnStartDrag;
property OnSelColorChange: TNotifyEvent read FOnChange write FOnChange;
property OnColorsChange: TNotifyEvent read FOnColorsChange write FOnColorsChange;
property OnPaintCell: TPaintCellEvent read FOnPaintCell write FOnPaintCell;
property OnCellClick: TCellClickEvent read FOnCellClick write FOnCellClick;
property OnGetHintText: TGetHintTextEvent read FOnGetHintText write FOnGetHintText;
property OnArrowKey: TArrowKeyEvent read FOnArrowKey write FOnArrowKey;
property OnContextPopup;
property OnMouseMove;
property OnMouseDown;
property OnMouseUp;
property OnKeyDown;
property OnKeyUp;
property OnKeyPress;
property OnResize;
property OnClick;
end ;
implementation
2016-12-16 14:22:33 +00:00
uses
mbUtils;
2016-12-11 22:56:25 +00:00
{ TmbColorPalette }
2016-12-08 23:14:26 +00:00
constructor TmbColorPalette. Create( AOwner: TComponent) ;
begin
2016-12-15 11:27:12 +00:00
inherited Create( AOwner) ;
2016-12-16 14:22:33 +00:00
// ControlStyle := ControlStyle - [csAcceptsControls] + [csOpaque];
2016-12-15 09:05:53 +00:00
// DoubleBuffered := true;
// PBack := TBitmap.Create;
// PBack.PixelFormat := pf32bit;
2016-12-15 11:27:12 +00:00
{$IFDEF DELPHI_7_UP} {$IFDEF DELPHI}
ParentBackground : = true ;
{$ENDIF} {$ENDIF}
TabStop : = true ;
ParentShowHint : = true ;
ShowHint : = false ;
2016-12-16 14:22:33 +00:00
SetInitialBounds( 0 , 0 , 1 8 0 , 1 2 6 ) ;
2016-12-15 11:27:12 +00:00
FMouseLoc : = mlNone;
FMouseOver : = false ;
FMouseDown : = false ;
FColCount : = 0 ;
FRowCount : = 0 ;
FIndex : = - 1 ;
FCheckedIndex : = - 1 ;
FTop : = 0 ;
FLeft : = 0 ;
FCellSize : = 1 8 ;
FState : = ccsNone;
FNames : = TStringList. Create;
FColors : = TStringList. Create;
( FColors as TStringList) . OnChange : = ColorsChange;
FTotalCells : = 0 ;
FHintFormat : = 'RGB(%r, %g, %b)' #13 'Hex: %hex' ;
FAutoHeight : = false ;
FMinColors : = 0 ;
FMaxColors : = 0 ;
FSort : = smNone;
FOrder : = soAscending;
FOld : = clNone;
FTStyle : = tsNone;
FCellStyle : = csDefault;
2016-12-08 23:14:26 +00:00
end ;
destructor TmbColorPalette. Destroy;
begin
2016-12-15 09:05:53 +00:00
//PBack.Free;
2016-12-16 14:22:33 +00:00
FBufferBmp. Free;
2016-12-09 23:47:46 +00:00
FNames. Free;
FColors. Free;
inherited Destroy;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. CalcAutoHeight;
begin
2016-12-09 23:47:46 +00:00
if Parent = nil then
exit;
FColCount : = Width div FCellSize;
2016-12-16 14:22:33 +00:00
{ 7
2016-12-09 23:47:46 +00:00
if FAutoHeight and ( FColCount < > 0 ) then
2016-12-08 23:14:26 +00:00
begin
2016-12-09 23:47:46 +00:00
if FColors. Count mod FColCount > 0 then
Height : = ( FColors. Count div FColCount + 1 ) * FCellSize
else
Height : = ( FColors. Count div FColCount) * FCellSize;
2016-12-08 23:14:26 +00:00
end ;
2016-12-09 23:47:46 +00:00
if Height = 0 then Height : = FCellSize;
2016-12-16 14:22:33 +00:00
}
2016-12-09 23:47:46 +00:00
FRowCount : = Height div FCellSize;
2016-12-16 14:22:33 +00:00
{
2016-12-09 23:47:46 +00:00
Width : = FColCount * FCellSize;
2016-12-16 14:22:33 +00:00
}
2016-12-08 23:14:26 +00:00
end ;
function TmbColorPalette. GetTotalRowCount: integer ;
begin
2016-12-09 23:47:46 +00:00
if FColCount < > 0 then
Result : = FTotalCells div FColCount
else
Result : = 0 ;
2016-12-08 23:14:26 +00:00
end ;
2016-12-16 14:22:33 +00:00
( *
2016-12-08 23:14:26 +00:00
procedure TmbColorPalette. CreateWnd;
begin
2016-12-15 11:27:12 +00:00
inherited ;
2016-12-16 14:22:33 +00:00
{
2016-12-15 11:27:12 +00:00
CalcAutoHeight;
Invalidate;
2016-12-16 14:22:33 +00:00
}
2016-12-08 23:14:26 +00:00
end ;
2016-12-16 14:22:33 +00:00
* )
2016-12-09 23:47:46 +00:00
( *
2016-12-08 23:14:26 +00:00
procedure TmbColorPalette. PaintParentBack;
{$IFDEF DELPHI_7_UP}
var
MemDC: HDC;
OldBMP: HBITMAP;
{$ENDIF}
begin
if PBack = nil then
begin
PBack : = TBitmap. Create;
PBack. PixelFormat : = pf32bit;
end ;
PBack. Width : = Width;
PBack. Height : = Height;
{$IFDEF FPC}
if Color = clDefault then
2016-12-09 23:47:46 +00:00
PBack. Canvas. Brush. Color : = GetDefaultColor( dctBrush)
2016-12-08 23:14:26 +00:00
else
{$ENDIF}
PBack. Canvas. Brush. Color : = Color;
PBack. Canvas. FillRect( PBack. Canvas. ClipRect) ;
{$IFDEF DELPHI_7_UP} {$IFDEF DELPHI}
if ParentBackground then
with ThemeServices do
if ThemesEnabled then
begin
MemDC : = CreateCompatibleDC( 0 ) ;
OldBMP : = SelectObject( MemDC, PBack. Handle) ;
DrawParentBackground( Handle, MemDC, nil , False ) ;
if OldBMP < > 0 then SelectObject( MemDC, OldBMP) ;
if MemDC < > 0 then DeleteDC( MemDC) ;
end ;
{$ENDIF} {$ENDIF}
2016-12-09 23:47:46 +00:00
end ; * )
2016-12-08 23:14:26 +00:00
procedure TmbColorPalette. Paint;
var
2016-12-09 23:47:46 +00:00
i: integer ;
2016-12-16 14:22:33 +00:00
bmp: TBitmap;
2016-12-08 23:14:26 +00:00
begin
2016-12-15 09:05:53 +00:00
{ PBack. Width : = Width;
2016-12-09 23:47:46 +00:00
PBack. Height : = Height;
PaintParentBack( PBack) ;
2016-12-15 09:05:53 +00:00
}
2016-12-09 23:47:46 +00:00
//make bmp
2016-12-16 14:22:33 +00:00
if FBufferBmp = nil then
FBufferBmp : = TBitmap. Create;
FBufferBmp. Width : = Width;
FBufferBmp. Height : = Height;
PaintParentBack( FBufferBmp) ;
FBufferBmp. Transparent : = false ; // a transparent bitmap does not show the selection ?!
2016-12-08 23:14:26 +00:00
//reset counters
2016-12-09 23:47:46 +00:00
FTotalCells : = FColors. Count - 1 ;
2016-12-08 23:14:26 +00:00
FTop : = 0 ;
FLeft : = 0 ;
2016-12-09 23:47:46 +00:00
2016-12-08 23:14:26 +00:00
//draw the cells
for i : = 0 to FColors. Count - 1 do
2016-12-09 23:47:46 +00:00
begin
2016-12-08 23:14:26 +00:00
if FColors. Strings[ i] < > '' then
2016-12-16 14:22:33 +00:00
DrawCell( FBufferBmp. Canvas, FColors. Strings[ i] ) ;
2016-12-08 23:14:26 +00:00
Inc( FLeft) ;
2016-12-09 23:47:46 +00:00
end ;
//draw the bmp
2016-12-16 14:22:33 +00:00
if Color = clDefault then
begin
// Use temporary bitmap to draw the buffer bitmap transparently
bmp : = TBitmap. Create;
try
bmp. SetSize( Width, Height) ;
if Color = clDefault then begin
bmp. Transparent : = true ;
bmp. TransparentColor : = clForm;
end ;
bmp. Canvas. Draw( 0 , 0 , FBufferBmp) ;
Canvas. Draw( 0 , 0 , bmp) ;
finally
bmp. Free;
end ;
end
else
Canvas. Draw( 0 , 0 , FBufferBmp) ;
2016-12-09 23:47:46 +00:00
//csDesiging border
2016-12-08 23:14:26 +00:00
if csDesigning in ComponentState then
2016-12-09 23:47:46 +00:00
begin
2016-12-08 23:14:26 +00:00
Canvas. Brush. Style : = bsClear;
Canvas. Pen. Style : = psDot;
Canvas. Pen. Color : = clBtnShadow;
Canvas. Rectangle( ClientRect) ;
Canvas. Brush. Style : = bsSolid;
Canvas. Pen. Style : = psSolid;
2016-12-09 23:47:46 +00:00
end ;
2016-12-08 23:14:26 +00:00
end ;
2016-12-16 14:22:33 +00:00
procedure TmbColorPalette. DrawCell( ACanvas: TCanvas; AColor: string ) ;
2016-12-08 23:14:26 +00:00
var
2016-12-09 23:47:46 +00:00
R: Trect;
FCurrentIndex: integer ;
c: TColor;
Handled: boolean ;
2016-12-08 23:14:26 +00:00
begin
2016-12-09 23:47:46 +00:00
// set props
2016-12-16 14:22:33 +00:00
if ( FLeft + 1 ) * FCellSize > Width then
2016-12-08 23:14:26 +00:00
begin
2016-12-09 23:47:46 +00:00
Inc( FTop) ;
FLeft : = 0 ;
2016-12-08 23:14:26 +00:00
end ;
2016-12-09 23:47:46 +00:00
FCurrentIndex : = FTop * FColCount + FLeft;
R : = Rect( FLeft * FCellSize, FTop * FCellSize, ( FLeft + 1 ) * FCellSize, ( FTop + 1 ) * FCellSize) ;
//start drawing
//get current state
if FCurrentIndex = FCheckedIndex then
2016-12-08 23:14:26 +00:00
begin
2016-12-09 23:47:46 +00:00
if FCheckedIndex = FIndex then
2016-12-08 23:14:26 +00:00
begin
2016-12-09 23:47:46 +00:00
if FMouseDown then
2016-12-08 23:14:26 +00:00
FState : = ccsDown
2016-12-09 23:47:46 +00:00
else
2016-12-08 23:14:26 +00:00
FState : = ccsCheckedHover;
end
2016-12-09 23:47:46 +00:00
else
FState : = ccsChecked;
end
else
if FIndex = FCurrentIndex then
case FMouseLoc of
2016-12-08 23:14:26 +00:00
mlNone: FState : = ccsNone;
mlOver: FState : = ccsOver;
2016-12-09 23:47:46 +00:00
end
else
FState : = ccsNone;
2016-12-08 23:14:26 +00:00
2016-12-09 23:47:46 +00:00
//paint
2016-12-16 14:22:33 +00:00
DrawCellBack( ACanvas, R, FCurrentIndex) ;
2016-12-08 23:14:26 +00:00
2016-12-09 23:47:46 +00:00
// fire the event
Handled : = false ;
2016-12-16 14:22:33 +00:00
c : = mbStringToColor( AColor) ;
2016-12-09 23:47:46 +00:00
if Assigned( FOnPaintCell) then
2016-12-08 23:14:26 +00:00
case FCellStyle of
2016-12-09 23:47:46 +00:00
csDefault:
2016-12-16 14:22:33 +00:00
FOnPaintCell( ACanvas, R, c, FCurrentIndex, FState, FTStyle, Handled) ;
2016-12-09 23:47:46 +00:00
csCorel:
if FColCount = 1 then
2016-12-16 14:22:33 +00:00
FOnPaintCell( ACanvas, R, c, FCurrentIndex, FState, FTStyle, Handled)
2016-12-09 23:47:46 +00:00
else
2016-12-16 14:22:33 +00:00
FOnPaintCell( ACanvas, Rect( R. Left, R. Top, R. Right + 1 , R. Bottom) , c,
FCurrentIndex, FState, FTStyle, Handled) ;
2016-12-08 23:14:26 +00:00
end ;
2016-12-09 23:47:46 +00:00
if not Handled then
begin
// if standard colors draw the rect
2016-12-16 14:22:33 +00:00
if not SameText( AColor, 'clCustom' ) and not SameText( AColor, 'clTransparent' ) then
2016-12-08 23:14:26 +00:00
case FCellStyle of
2016-12-09 23:47:46 +00:00
csDefault:
2016-12-08 23:14:26 +00:00
begin
2016-12-09 23:47:46 +00:00
InflateRect( R, - 3 , - 3 ) ;
if Enabled then
begin
2016-12-16 14:22:33 +00:00
ACanvas. Brush. Color : = c;
ACanvas. Pen. Color : = clBtnShadow;
2016-12-09 23:47:46 +00:00
end
else
begin
2016-12-16 14:22:33 +00:00
ACanvas. Brush. Color : = clGray;
ACanvas. Pen. Color : = clGray;
2016-12-09 23:47:46 +00:00
end ;
2016-12-16 14:22:33 +00:00
ACanvas. Rectangle( R) ;
2016-12-09 23:47:46 +00:00
Exit;
2016-12-08 23:14:26 +00:00
end ;
2016-12-09 23:47:46 +00:00
csCorel:
2016-12-08 23:14:26 +00:00
begin
2016-12-09 23:47:46 +00:00
if ( FState < > ccsNone) then
InflateRect( R, - 2 , - 2 )
else
begin
Inc( R. Left) ;
Dec( R. Bottom) ;
if R. Top < = 1 then
Inc( R. Top) ;
if R. Right = Width then
Dec( R. Right) ;
end ;
if Enabled then
2016-12-16 14:22:33 +00:00
ACanvas. Brush. Color : = c
2016-12-09 23:47:46 +00:00
else
2016-12-16 14:22:33 +00:00
ACanvas. Brush. Color : = clGray;
ACanvas. FillRect( R) ;
2016-12-09 23:47:46 +00:00
Exit;
2016-12-08 23:14:26 +00:00
end ;
end ;
2016-12-09 23:47:46 +00:00
//if transparent draw the glyph
2016-12-16 14:22:33 +00:00
if SameText( AColor, 'clTransparent' ) then
PaintTransparentGlyph( ACanvas, R) ;
2016-12-08 23:14:26 +00:00
end ;
end ;
procedure TmbColorPalette. DrawCellBack( ACanvas: TCanvas; R: TRect; AIndex: integer ) ;
begin
case FCellStyle of
csDefault:
begin
{$IFDEF DELPHI_7_UP}
if ThemeServices. ThemesEnabled then
begin
with ThemeServices do
if Enabled then
case FState of
2016-12-16 14:22:33 +00:00
ccsNone: ; //PaintParentBack(ACanvas, R);
// ccsNone: ACanvas.CopyRect(R, PBack.Canvas, R);
2016-12-08 23:14:26 +00:00
ccsOver: DrawElement( ACanvas. Handle, GetElementDetails( ttbButtonHot) , R) ;
ccsDown: DrawElement( ACanvas. Handle, GetElementDetails( ttbButtonPressed) , R) ;
ccsChecked: DrawElement( ACanvas. Handle, GetElementDetails( ttbButtonChecked) , R) ;
ccsCheckedHover: DrawElement( ACanvas. Handle, GetElementDetails( ttbButtonCheckedHot) , R) ;
end
else
DrawElement( ACanvas. Handle, GetElementDetails( ttbButtonDisabled) , R) ;
end
else
{$ENDIF}
if Enabled then
case FState of
ccsNone: ACanvas. FillRect( R) ;
ccsOver: DrawEdge( ACanvas. Handle, R, BDR_RAISEDINNER, BF_RECT) ;
ccsDown, ccsChecked, ccsCheckedHover: DrawEdge( ACanvas. Handle, R, BDR_SUNKENOUTER, BF_RECT) ;
end
else
DrawFrameControl( ACanvas. Handle, R, DFC_BUTTON, 0 or DFCS_BUTTONPUSH or DFCS_FLAT or DFCS_INACTIVE) ;
end ;
csCorel:
begin
if Enabled then
begin
{$IFDEF DELPHI_7_UP}
if ThemeServices. ThemesEnabled then
case FState of
ccsNone:
begin
ACanvas. Brush. Color : = clWhite;
ACanvas. Pen. Color : = clBlack;
//left
ACanvas. MoveTo( R. Left, R. Top) ;
ACanvas. LineTo( R. Left, R. Bottom- 1 ) ;
//bottom
ACanvas. MoveTo( R. Left, R. Bottom- 1 ) ;
ACanvas. LineTo( R. Right, R. Bottom- 1 ) ;
//top
if R. Top = 0 then
begin
ACanvas. MoveTo( R. Left, R. Top) ;
ACanvas. LineTo( R. Right, R. Top) ;
end ;
//right
if ( R. Right = Width) then
begin
ACanvas. MoveTo( R. Right- 1 , R. Top) ;
ACanvas. LineTo( R. Right- 1 , R. Bottom- 1 ) ;
end
else
if ( AIndex = FTotalCells) then
begin
ACanvas. MoveTo( R. Right, R. Top) ;
ACanvas. LineTo( R. Right, R. Bottom) ;
end ;
end ;
ccsOver: ThemeServices. DrawElement( ACanvas. Handle, ThemeServices. GetElementDetails( ttbButtonHot) , R) ;
ccsDown: ThemeServices. DrawElement( ACanvas. Handle, ThemeServices. GetElementDetails( ttbButtonPressed) , R) ;
ccsChecked: ThemeServices. DrawElement( ACanvas. Handle, ThemeServices. GetElementDetails( ttbButtonChecked) , R) ;
ccsCheckedHover: ThemeServices. DrawElement( ACanvas. Handle, ThemeServices. GetElementDetails( ttbButtonCheckedHot) , R) ;
end
else
{$ENDIF}
case FState of
ccsNone:
begin
ACanvas. Brush. Color : = clWhite;
ACanvas. Pen. Color : = clBlack;
ACanvas. Brush. Color : = clWhite;
ACanvas. Pen. Color : = clBlack;
//left
ACanvas. MoveTo( R. Left, R. Top) ;
ACanvas. LineTo( R. Left, R. Bottom- 1 ) ;
//bottom
ACanvas. MoveTo( R. Left, R. Bottom- 1 ) ;
ACanvas. LineTo( R. Right, R. Bottom- 1 ) ;
//top
if R. Top = 0 then
begin
ACanvas. MoveTo( R. Left, R. Top) ;
ACanvas. LineTo( R. Right, R. Top) ;
end ;
//right
if ( R. Right = Width) then
begin
ACanvas. MoveTo( R. Right- 1 , R. Top) ;
ACanvas. LineTo( R. Right- 1 , R. Bottom- 1 ) ;
end
else
if ( AIndex = FTotalCells) then
begin
ACanvas. MoveTo( R. Right, R. Top) ;
ACanvas. LineTo( R. Right, R. Bottom) ;
end ;
end ;
ccsOver:
begin
OffsetRect( R, 1 , 1 ) ;
DrawEdge( ACanvas. Handle, R, BDR_RAISED, BF_RECT) ;
end ;
ccsDown, ccsChecked, ccsCheckedHover: DrawEdge( ACanvas. Handle, R, BDR_SUNKENOUTER, BF_RECT) ;
end ;
end
else
{$IFDEF DELPHI_7_UP}
if ThemeServices. ThemesEnabled then
ThemeServices. DrawElement( ACanvas. Handle, ThemeServices. GetElementDetails( ttbButtonDisabled) , R)
else
{$ENDIF}
begin
2016-12-09 23:47:46 +00:00
{$IFDEF FPC}
if Color = clDefault then
ACanvas. Brush. Color : = GetDefaultColor( dctBrush) else
{$ENDIF}
2016-12-08 23:14:26 +00:00
ACanvas. Brush. Color : = Color;
ACanvas. FillRect( R) ;
end ;
end ;
end ;
end ;
procedure TmbColorPalette. PaintTransparentGlyph( ACanvas: TCanvas; R: TRect) ;
begin
2016-12-15 11:27:12 +00:00
InflateRect( R, - 3 , - 3 ) ;
if FCellStyle = csCorel then
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
if FState < > ccsNone then
InflateRect( R, - 2 , - 2 )
else if FColCount > 1 then
Inc( R. Right) ;
2016-12-08 23:14:26 +00:00
end ;
2016-12-16 14:22:33 +00:00
2016-12-15 11:27:12 +00:00
with ACanvas do
case FTStyle of
tsPhotoshop:
begin
if Enabled then
Pen. Color : = clBtnShadow
else
Pen. Color : = clGray;
Brush. Color : = clWhite;
Rectangle( R) ;
Brush. Color : = clSilver;
FillRect( Rect( R. Left + ( R. Right - R. Left) div 2 , R. Top + 1 , R. Right - 1 , R. Top + ( R. Bottom - R. Top) div 2 ) ) ;
FillRect( Rect( R. Left + 1 , R. Top + ( R. Bottom - R. Top) div 2 , R. Left + ( R. Right - R. Left) div 2 , R. Bottom - 1 ) ) ;
end ;
tsPhotoshop2:
begin
InflateRect( R, - 1 , - 1 ) ;
Brush. Color : = clWhite;
Rectangle( R) ;
Pen. Color : = clRed;
Pen. Width : = 2 ;
InflateRect( R, 1 , 1 ) ;
MoveTo( R. Left, R. Top) ;
LineTo( R. Right - 1 , R. Bottom - 1 ) ;
Pen. Width : = 1 ;
Pen. Color : = clBlack;
end ;
tsCorel:
begin
if FCellStyle = csCorel then
begin
Pen. Color : = clBlack;
InflateRect( R, 3 , 3 ) ;
Brush. Color : = clWhite;
Rectangle( R) ;
//the \ line
MoveTo( R. Left, R. Top) ;
LineTo( R. Right, R. Bottom) ;
//the / line
MoveTo( R. Right- 1 , R. Top) ;
LineTo( R. Left- 1 , R. Bottom) ;
end
else
begin
if Enabled then
Pen. Color : = clBtnShadow
else
Pen. Color : = clGray;
Brush. Color : = clWhite;
Rectangle( R) ;
MoveTo( R. Left, R. Top) ;
LineTo( R. Right, R. Bottom) ;
MoveTo( R. Right - 1 , R. Top) ;
LineTo( R. Left - 1 , R. Bottom) ;
end ;
end ;
tsMicroangelo:
begin
InflateRect( R, - 1 , - 1 ) ;
Dec( R. Bottom) ;
Pen. Color : = clBlack;
Brush. Color : = clTeal;
Rectangle( R) ;
Pixels[ R. Left + 2 , R. Top + 2 ] : = clWhite;
Pixels[ R. Left + ( R. Right - R. Left) div 2 , R. Bottom] : = clBlack;
MoveTo( R. Left + ( R. Right - R. Left) div 2 - 2 , R. Bottom + 1 ) ;
LineTo( R. Left + ( R. Right - R. Left) div 2 + 3 , R. Bottom + 1 ) ;
end ;
2016-12-08 23:14:26 +00:00
end ;
end ;
procedure TmbColorPalette. Resize;
begin
2016-12-15 11:27:12 +00:00
inherited ;
2016-12-16 14:22:33 +00:00
CalcAutoHeight; // wp: will cause a ChangedBounds endless loop
2016-12-15 11:27:12 +00:00
Invalidate;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. CMMouseEnter(
var Message : {$IFDEF DELPHI} TMessage{$ELSE} TLMessage{$ENDIF} ) ;
begin
2016-12-15 11:27:12 +00:00
FMouseOver : = true ;
FMouseLoc : = mlOver;
Invalidate;
inherited ;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. CMMouseLeave(
var Message : {$IFDEF DELPHI} TMessage{$ELSE} TLMessage{$ENDIF} ) ;
begin
2016-12-15 11:27:12 +00:00
FMouseOver : = false ;
FMouseLoc : = mlNone;
FIndex : = - 1 ;
Invalidate;
inherited ;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. MouseMove( Shift: TShiftState; X, Y: Integer ) ;
2016-12-09 23:47:46 +00:00
var
newIndex: Integer ;
2016-12-08 23:14:26 +00:00
begin
2016-12-09 23:47:46 +00:00
newIndex : = ( y div FCellSize) * FColCount + ( x div FCellSize) ;
if FIndex < > newIndex then
2016-12-08 23:14:26 +00:00
begin
2016-12-09 23:47:46 +00:00
FIndex : = newIndex;
if FIndex > FTotalCells then FIndex : = - 1 ;
Invalidate;
2016-12-08 23:14:26 +00:00
end ;
2016-12-09 23:47:46 +00:00
inherited ;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. MouseDown( Button: TMouseButton; Shift: TShiftState; X, Y: Integer ) ;
begin
2016-12-15 11:27:12 +00:00
if Button = mbLeft then
begin
SetFocus;
FMouseDown : = true ;
FMouseLoc : = mlDown;
if ( y div FCellSize) * FColCount + ( x div FCellSize) < = FTotalCells then
if FCheckedIndex < > ( y div FCellSize) * FColCount + ( x div FCellSize) then
begin
FOldIndex : = FCheckedIndex;
FCheckedIndex : = ( y div FCellSize) * FColCount + ( x div FCellSize) ;
end ;
Invalidate;
end ;
inherited ;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. Click;
begin
2016-12-15 11:27:12 +00:00
inherited ;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. MouseUp( Button: TMouseButton; Shift: TShiftState; X, Y: Integer ) ;
var
2016-12-09 23:47:46 +00:00
DontCheck: boolean ;
AColor: TColor;
2016-12-08 23:14:26 +00:00
begin
2016-12-09 23:47:46 +00:00
FMouseDown : = false ;
if FMouseOver then
FMouseLoc : = mlOver
else
FMouseLoc : = mlNone;
DontCheck : = false ;
if ( FCheckedIndex > - 1 ) and ( FCheckedIndex < FColors. Count) then
AColor : = mbStringToColor( FColors. Strings[ FCheckedIndex] )
else
AColor : = clNone;
if ( Button = mbLeft) and PtInRect( ClientRect, Point( x, y) ) then
if Assigned( FOnCellClick) then
FOnCellClick( Button, Shift, FCheckedIndex, AColor, DontCheck) ;
if DontCheck then FCheckedIndex : = FOldIndex;
Invalidate;
inherited ;
if Assigned( FOnChange) then FOnChange( Self) ;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. CMGotFocus(
var Message : {$IFDEF DELPHI} TMessage{$ELSE} TLMessage{$ENDIF} ) ;
begin
2016-12-09 23:47:46 +00:00
inherited ;
Invalidate;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. CMLostFocus(
var Message : {$IFDEF DELPHI} TMessage{$ELSE} TLMessage{$ENDIF} ) ;
begin
2016-12-09 23:47:46 +00:00
inherited ;
if FMouseOver then
FMouseLoc : = mlOver
else
FMouseLoc : = mlNone;
Invalidate;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. CMEnabledChanged(
var Message : {$IFDEF DELPHI} TMessage{$ELSE} TLMessage{$ENDIF} ) ;
begin
2016-12-09 23:47:46 +00:00
inherited ;
Invalidate;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. SelectCell( i: integer ) ;
begin
2016-12-09 23:47:46 +00:00
if i < FColors. Count - 1 then
FCheckedIndex : = i
else
FCheckedIndex : = - 1 ;
Invalidate;
if Assigned( FOnChange) then FOnChange( Self) ;
2016-12-08 23:14:26 +00:00
end ;
function TmbColorPalette. GetSelColor: TColor;
begin
2016-12-09 23:47:46 +00:00
if ( FCheckedIndex > - 1 ) and ( FCheckedIndex < = FTotalCells) then
Result : = mbStringToColor( FColors. Strings[ FCheckedIndex] )
else
Result : = FOld;
2016-12-08 23:14:26 +00:00
end ;
function TmbColorPalette. GetColorUnderCursor: TColor;
begin
2016-12-09 23:47:46 +00:00
Result : = clNone;
if FIndex > - 1 then
if FIndex < FColors. Count then
Result : = mbStringToColor( FColors. Strings[ FIndex] ) ;
2016-12-08 23:14:26 +00:00
end ;
function TmbColorPalette. GetIndexUnderCursor: integer ;
begin
2016-12-09 23:47:46 +00:00
Result : = - 1 ;
if FIndex > - 1 then
if FIndex < FColors. Count then
Result : = FIndex;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. SetTStyle( s: TTransparentStyle) ;
begin
2016-12-09 23:47:46 +00:00
if FTStyle < > s then
2016-12-08 23:14:26 +00:00
begin
2016-12-09 23:47:46 +00:00
FTStyle : = s;
Invalidate;
2016-12-08 23:14:26 +00:00
end ;
end ;
procedure TmbColorPalette. SetCellStyle( s: TCellStyle) ;
begin
2016-12-15 11:27:12 +00:00
if FCellStyle < > s then
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
FCellStyle : = s;
Invalidate;
2016-12-08 23:14:26 +00:00
end ;
end ;
procedure TmbColorPalette. SetSelColor( k: TColor) ;
var
2016-12-15 11:27:12 +00:00
s: string ;
i: integer ;
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
s : = mbColorToString( k) ;
for i: = 0 to FColors. Count - 1 do
if SameText( s, FColors. Strings[ i] ) then
begin
FCheckedIndex : = i;
Break;
end
else
FCheckedIndex : = - 1 ;
Invalidate;
FOld : = k;
if Assigned( FOnChange) then FOnChange( Self) ;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. SetStrings( s: TStrings) ;
var
2016-12-15 11:27:12 +00:00
i: integer ;
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
FColors. Clear;
FColors. AddStrings( s) ;
if FColors. Count < FMinColors then
for i : = 0 to FMinColors - FColors. Count - 1 do
FColors. Add( 'clNone' ) ;
if ( FColors. Count > FMaxColors) and ( FMaxColors > 0 ) then
for i : = FColors. Count - 1 downto FMaxColors do
FColors. Delete( i) ;
CalcAutoHeight;
SortColors;
Invalidate;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. SetNames( n: TStrings) ;
var
2016-12-15 11:27:12 +00:00
i: integer ;
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
FNames. Clear;
FNames. AddStrings( n) ;
if ( FNames. Count > FMaxColors) and ( FMaxColors > 0 ) then
for i : = FNames. Count - 1 downto FMaxColors do
FNames. Delete( i) ;
2016-12-08 23:14:26 +00:00
end ;
function TmbColorPalette. GetMoveCellIndex( move: TMoveDirection) : integer ;
var
2016-12-15 11:27:12 +00:00
FBefore: integer ;
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
Result : = - 1 ;
case move of
mdLeft:
if FCheckedIndex - 1 < 0 then
Result : = FTotalCells
else
Result : = FCheckedIndex - 1 ;
mdRight:
if FCheckedIndex + 1 > FTotalCells then
Result : = 0
else
Result : = FCheckedIndex + 1 ;
mdUp:
if FCheckedIndex - FColCount < 0 then
begin
FBefore : = ( FTotalcells div FColCount) * FColCount;
if FBefore + FCheckedIndex - 1 > FTotalCells then Dec( FBefore, FColCount) ;
Result : = FBefore + FCheckedIndex - 1 ;
end
else
Result : = FCheckedIndex - FColCount;
mdDown:
if FCheckedIndex + FColCount > FTotalCells then
Result : = FCheckedIndex mod FColCount + 1
else
Result : = FCheckedIndex + FColCount;
end ;
if Result > FColors. Count - 1 then
Result : = 0 ;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. CNKeyDown(
var Message : {$IFDEF DELPHI} TWMKeyDown{$ELSE} TLMKeyDown{$ENDIF} ) ;
var
2016-12-15 11:27:12 +00:00
FInherited: boolean ;
Shift: TShiftState;
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
Shift : = KeyDataToShiftState( Message . KeyData) ;
Finherited : = false ;
case Message . CharCode of
VK_LEFT:
begin
FCheckedIndex : = GetMoveCellIndex( mdLeft) ;
if Assigned( FOnArrowKey) then FOnArrowKey( Message . CharCode, Shift) ;
end ;
VK_RIGHT:
begin
FCheckedIndex : = GetMoveCellIndex( mdRight) ;
if Assigned( FOnArrowKey) then FOnArrowKey( Message . CharCode, Shift) ;
end ;
VK_UP:
begin
FCheckedIndex : = GetMoveCellIndex( mdUp) ;
if Assigned( FOnArrowKey) then FOnArrowKey( Message . CharCode, Shift) ;
end ;
VK_DOWN:
begin
FCheckedIndex : = GetMoveCellIndex( mdDown) ;
if Assigned( FOnArrowKey) then FOnArrowKey( Message . CharCode, Shift) ;
end ;
VK_SPACE, VK_RETURN:
if Assigned( FOnChange) then FOnChange( Self) ;
else
begin
FInherited : = true ;
inherited ;
end ;
2016-12-08 23:14:26 +00:00
end ;
2016-12-15 11:27:12 +00:00
if not FInherited then
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
Invalidate;
if Assigned( OnKeyDown) then OnKeyDown( Self, Message . CharCode, Shift) ;
if Assigned( FOnChange) then FOnChange( Self) ;
2016-12-08 23:14:26 +00:00
end ;
end ;
procedure TmbColorPalette. CMHintShow(
var Message : {$IFDEF DELPHI} TMessage{$ELSE} TLMessage{$ENDIF} ) ;
var
2016-12-15 11:27:12 +00:00
clr: TColor;
Handled: boolean ;
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
if ( Colors. Count > 0 ) and ( FIndex > - 1 ) then
with TCMHintShow( Message ) do
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
if not ShowHint then
Message . Result : = 1
else
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
with HintInfo^ do
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
// show that we want a hint
Result : = 0 ;
ReshowTimeout : = 1 ;
HideTimeout : = 5 0 0 0 ;
clr : = GetColorUnderCursor;
//fire event
Handled : = false ;
if Assigned( FOnGetHintText) then
FOnGetHintText( clr, GetIndexUnderCursor, HintStr, Handled) ;
if Handled then Exit;
//do default
if FIndex < FNames. Count then
HintStr : = FNames. Strings[ FIndex]
else
2016-12-08 23:14:26 +00:00
if SameText( FColors. Strings[ GetIndexUnderCursor] , 'clCustom' ) or SameText( FColors. Strings[ GetIndexUnderCursor] , 'clTransparent' ) then
2016-12-15 11:27:12 +00:00
HintStr : = StringReplace( FColors. Strings[ GetIndexUnderCursor] , 'cl' , '' , [ rfReplaceAll] )
2016-12-08 23:14:26 +00:00
else
2016-12-15 11:27:12 +00:00
HintStr : = FormatHint( FHintFormat, GetColorUnderCursor) ;
2016-12-08 23:14:26 +00:00
end ;
end ;
end ;
end ;
procedure TmbColorPalette. SetAutoHeight( auto: boolean ) ;
begin
2016-12-15 11:27:12 +00:00
FAutoHeight : = auto;
CalcAutoHeight;
Invalidate;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. SetMinColors( m: integer ) ;
var
2016-12-15 11:27:12 +00:00
i: integer ;
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
if ( FMaxColors > 0 ) and ( m > FMaxColors) then
m : = FMaxColors;
FMinColors : = m;
if FColors. Count < m then
for i : = 0 to m - FColors. Count - 1 do
FColors. Add( 'clNone' ) ;
CalcAutoHeight;
SortColors;
Invalidate;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. SetMaxColors( m: integer ) ;
var
2016-12-15 11:27:12 +00:00
i: integer ;
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
if m < 0 then m : = 0 ;
FMaxColors : = m;
if ( m < FMinColors) and ( m > 0 ) then
SetMinColors( m) ;
if ( FColors. Count > FMaxColors) and ( FMaxColors > 0 ) then
for i : = FColors. Count - 1 downto FMaxColors do
FColors. Delete( i) ;
CalcAutoHeight;
SortColors;
Invalidate;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. SetSortMode( s: TSortMode) ;
begin
2016-12-15 11:27:12 +00:00
if FSort < > s then
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
FSort : = s;
SortColors;
Invalidate;
2016-12-08 23:14:26 +00:00
end ;
end ;
procedure TmbColorPalette. SetSortOrder( s: TSortOrder) ;
begin
2016-12-15 11:27:12 +00:00
if FOrder < > s then
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
FOrder : = s;
SortColors;
Invalidate;
2016-12-08 23:14:26 +00:00
end ;
end ;
procedure TmbColorPalette. ColorsChange( Sender: TObject) ;
begin
2016-12-15 11:27:12 +00:00
if Assigned( FOnColorsChange) then FOnColorsChange( Self) ;
FTotalCells : = FColors. Count - 1 ;
CalcAutoHeight;
Invalidate;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. SetCellSize( s: integer ) ;
begin
2016-12-15 11:27:12 +00:00
FCellSize : = s;
CalcAutoHeight;
Invalidate;
2016-12-08 23:14:26 +00:00
end ;
function TmbColorPalette. GetSelectedCellRect: TRect;
var
2016-12-15 11:27:12 +00:00
row, fbottom, fleft: integer ;
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
if FCheckedIndex > - 1 then
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
if FCheckedIndex mod FColCount = 0 then
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
row : = FCheckedIndex div FColCount;
fleft : = Width - FCellSize;
2016-12-08 23:14:26 +00:00
end
2016-12-15 11:27:12 +00:00
else
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
row : = FCheckedIndex div FColCount + 1 ;
fleft : = ( FCheckedIndex mod FColCount - 1 ) * FCellSize;
2016-12-08 23:14:26 +00:00
end ;
2016-12-15 11:27:12 +00:00
fbottom : = row * FCellSize;
Result : = Rect( fleft, fbottom - FCellSize, fleft + FCellSize, fbottom) ;
2016-12-08 23:14:26 +00:00
end
2016-12-15 11:27:12 +00:00
else
Result : = Rect( 0 , 0 , 0 , 0 ) ;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. GeneratePalette( BaseColor: TColor) ;
begin
2016-12-15 11:27:12 +00:00
FColors. Text : = MakePalette( BaseColor, FOrder) ;
CalcAutoHeight;
SortColors;
Invalidate;
if Assigned( FOnChange) then FOnChange( Self) ;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. GenerateGradientPalette( Colors: array of TColor) ;
begin
2016-12-15 11:27:12 +00:00
FColors. Text : = MakeGradientPalette( Colors) ;
CalcAutoHeight;
SortColors;
Invalidate;
if Assigned( FOnChange) then FOnChange( Self) ;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. LoadPalette( FileName: TFileName) ;
var
2016-12-15 11:27:12 +00:00
supported: boolean ;
a: AcoColors;
i: integer ;
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
supported : = false ;
if SameText( ExtractFileExt( FileName) , '.pal' ) then
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
supported : = true ;
FNames. Clear;
FColors. Text : = ReadJASCPal( FileName) ;
2016-12-08 23:14:26 +00:00
end
2016-12-15 11:27:12 +00:00
else if SameText( ExtractFileExt( FileName) , '.aco' ) then
begin
2016-12-08 23:14:26 +00:00
supported : = true ;
a : = ReadPhotoshopAco( FileName) ;
FColors. Clear;
for i : = 0 to Length( a. Colors) - 1 do
2016-12-15 11:27:12 +00:00
FColors. Add( ColorToString( a. Colors[ i] ) ) ;
2016-12-08 23:14:26 +00:00
FNames. Clear;
if a. HasNames then
2016-12-15 11:27:12 +00:00
for i : = 0 to Length( a. Names) - 1 do
FNames. Add( a. Names[ i] ) ;
end
else if SameText( ExtractFileExt( FileName) , '.act' ) then
begin
supported : = true ;
FNames. Clear;
FColors. Text : = ReadPhotoshopAct( FileName) ;
end
2016-12-08 23:14:26 +00:00
else
2016-12-15 11:27:12 +00:00
raise Exception. Create( 'The file format you are trying to load is not supported in this version of the palette' #13 'Please send a request to MXS along with the files of this format so' #13 'loading support for this file can be added too' ) ;
if supported then
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
CalcAutoHeight;
SortColors;
Invalidate;
if Assigned( FOnChange) then FOnChange( Self) ;
2016-12-08 23:14:26 +00:00
end ;
end ;
procedure TmbColorPalette. SaveColorsAsPalette( FileName: TFileName) ;
begin
2016-12-15 11:27:12 +00:00
if SameText( ExtractFileExt( FileName) , '.pal' ) then
SaveJASCPal( FColors, FileName)
else
raise Exception. Create( 'The file extension specified does not identify a supported file format!' #13 'Supported files formats are: .pal .aco .act' ) ;
2016-12-08 23:14:26 +00:00
end ;
procedure TmbColorPalette. SortColors;
var
2016-12-15 11:27:12 +00:00
old: TColor;
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
if FSort < > smNone then
2016-12-08 23:14:26 +00:00
begin
2016-12-15 11:27:12 +00:00
if FColors. Count = 0 then Exit;
old : = GetSelColor;
SortPalColors( FColors, FSort, FOrder) ;
SetSelColor( old) ;
Invalidate;
2016-12-08 23:14:26 +00:00
end ;
end ;
end .