Difference between revisions of "ColorPalette"

From Lazarus wiki
Jump to navigationJump to search
(Update to current version)
(Remove OnSelectColor and related. Update change log, version info)
Line 3: Line 3:
 
==About==
 
==About==
 
[[Image:ColorPalette.png|right|ColorPalette]]
 
[[Image:ColorPalette.png|right|ColorPalette]]
ColorPalette is a cross-platform color palette grid with ability to select a color from a palette. The OnSelectColor event is fired when the user clicks onto a color.
+
ColorPalette is a cross-platform color palette grid with ability to select a color from a palette. The OnMouseColorPick event is fired when the user clicks onto a color.
 
===Authors===
 
===Authors===
 
[[User:Tombo|Tom Gregorovic]] and Werner Pamler
 
[[User:Tombo|Tom Gregorovic]] and Werner Pamler
Line 12: Line 12:
 
==Usage==
 
==Usage==
 
===Color selection===
 
===Color selection===
When a color is selected by clicking with the mouse onto a color box an event <tt>OnSelectColor</tt> is generated; the event gets the rgb value of the selected color as a parameter. If the property <tt>ShowSelection</tt> is turned on then the selected color is highlighted.
+
When a color is selected by clicking with the mouse onto a color box an event <tt>OnColorPick</tt> is generated; the event gets the rgb value of the ''picked color'' as a parameter. Another parameter passes the ''ShiftState'' active during the click; usually this identifies the mouse button pressed. If the property <tt>ShowSelection</tt> is turned on then the picked color is highlighted.
  
The mouse button needed to fire this event is defined by the property <tt>PickShift</tt> which is a set of <tt>ssLeft, ssRight, ssMiddle</tt> <tt>TShiftState</tt> elements. The default value is <tt>ssLeft</tt>, i.e. the color is selected by the left mouse button.
+
While the mouse is dragged an event <tt>OnColorMouseMove</tt> is fired. Again, it has the color underneath the mouse cursor as well as the ShiftState as parameters. It can be used to update a color info display on the form.
  
{{Note|If a context menu is assigned to the component, for example with commands for color editing or deletion, it is recommended to add <tt>ssRight</tt> to the <tt>PickShift</tt>; this way the color box which was clicked for opening the context menu will be selected automatically.}}
+
The time flow when exactly the color is selected is determined by the property <tt>PickMode</tt>:
 
+
*<tt>pmImmediate</tt>: The color is selected, and the event is generated, when the mouse button goes down.
The time flow when exactly the color is selected is determined by another property, <tt>PickMode</tt>:
+
*<tt>pmContinuous</tt>: The color is selected, and the event is generated, while the mouse moves and when the mouse button goes up.
*<tt>pmImmediate</tt>: The color is selected, and the event is generated, when the mousebutton goes down.
+
*<tt>pmDefault</tt>: The color is selected when the mouse button goes down, and the event is generated when the mouse button goes up. Both events must occur at the same location. This mode is a left-over from a previous version of the component and should not be used any more.
*<tt>pmContinuous</tt>: The color is selected, and the event is generated, while the mouse moves (with the button according to <tt>PickShift</tt> pressed down), and when the mousebutton goes up.
 
*<tt>pmDefault</tt>: The color is selected when the mousebutton goes down, and the event is generated when the mousebutton goes up. Both events must occur at the same location. This mode is a left-over from a previous version of the component and should not be used any more.
 
  
 
===Palettes===
 
===Palettes===
Line 66: Line 64:
 
* Access individual colors by using the <tt>Colors[Index]</tt> property.
 
* Access individual colors by using the <tt>Colors[Index]</tt> property.
 
* <tt>ColorCount</tt> returns the number of colors in the palette.
 
* <tt>ColorCount</tt> returns the number of colors in the palette.
* <tt>SelectedColor</tt>: returns the currently selected color
+
* <tt>PickedColor</tt>: returns the currently selected color
* <tt>SelectedIndex</tt>: returns the index of the currently selected color (indexes are counted first along the rows).
+
* <tt>PickedIndex</tt>: returns the index of the currently selected color (indexes are counted first along the rows).
 
* <tt>MouseColor</tt>: returns the color of the button underneath the mouse cursor
 
* <tt>MouseColor</tt>: returns the color of the button underneath the mouse cursor
 
* <tt>MouseIndex</tt>: returns the index of the color underneath the mouse cursor (indexes are counted first along the rows).
 
* <tt>MouseIndex</tt>: returns the index of the color underneath the mouse cursor (indexes are counted first along the rows).
Line 82: Line 80:
 
* <tt>ButtonBorderColor</tt>: defines the borderline around a color button. Can be removed by selecting <tt>clNone</tt>.
 
* <tt>ButtonBorderColor</tt>: defines the borderline around a color button. Can be removed by selecting <tt>clNone</tt>.
 
* <tt>Color</tt>: defines the background color of the component. Note that the background is not visible if <ttButtondistance = 0</tt>.
 
* <tt>Color</tt>: defines the background color of the component. Note that the background is not visible if <ttButtondistance = 0</tt>.
* <tt>ShowColorHint</tt>: If true a hint popup window is displayed for the color button above which the mouse cursor hovers. The built-in hint text can be modified by means of the <tt>OnGetHintText</tt> event.
 
 
* <tt>ShowSelection</tt>: If true a thick border is drawn around the button of the selected color.
 
* <tt>ShowSelection</tt>: If true a thick border is drawn around the button of the selected color.
 
* <tt>UseSpacers</tt>: If true <tt>clNone</tt> color entries serve as spacers to arrange groups of colors. If false <tt>clNone</tt> is shown as a crossed-out button meaning "transparent color".
 
* <tt>UseSpacers</tt>: If true <tt>clNone</tt> color entries serve as spacers to arrange groups of colors. If false <tt>clNone</tt> is shown as a crossed-out button meaning "transparent color".
 +
==== Hints ====
 +
* <tt>ShowColorHint</tt>: If true a hint popup window is displayed for the color button above which the mouse cursor hovers. The built-in hint text can be modified by means of the <tt>OnGetHintText</tt> event.
 +
* The <tt>OnGetHintText</tt> allows to modify the built-in text used for creating the popup hint.
  
 
===Demo project===
 
===Demo project===
A demo project is contained in the folder ''demo'' of the component installation directory. It shows application of all the features of TColorPalette.
+
Two demo projects are contained in the folder ''demo'' of the component installation directory:
 +
* '''GeneralDemo''' shows application of all the features of TColorPalette.
 +
* '''ToolbarDemo''' adds a ColorPalette to a coolbar/toolar.
  
 
==Download and installation==
 
==Download and installation==
Line 96: Line 98:
 
=== Version 0.2===
 
=== Version 0.2===
 
* '''New features'''
 
* '''New features'''
** New color selection
 
 
** "AddColor", "DeleteColor" etc.
 
** "AddColor", "DeleteColor" etc.
 
** Color names
 
** Color names
 
** Builtin palettes
 
** Builtin palettes
 +
** Highlight selected color
 
** Color button distance, border color
 
** Color button distance, border color
 
** Color hint window
 
** Color hint window
 
+
* '''Tested''' on Windows 2000/XP/7/10, and with gtk2 and qt under Linux (Mint 17).
* '''Incompatible changes'''
 
** Different behavior of color selection (the old method corresponds to <tt>PickMode=pmDefault</tt>).
 
  
 
=== Version 0.1 ===
 
=== Version 0.1 ===
* Initial release
+
* '''Initial release'''
 
+
* '''Tested''' on Windows XP, and with gtk1 and gtk2 under Linux (Kubuntu 6.06).
==Notes==
 
 
 
* Tested on Windows XP.
 
* Tested with gtk1 and gtk2 under Linux (Kubuntu 6.06).
 
  
 
[[Category:Components]]
 
[[Category:Components]]
 
[[Category:Lazarus-CCR]]
 
[[Category:Lazarus-CCR]]

Revision as of 13:51, 28 August 2015

English (en) français (fr)

About

ColorPalette

ColorPalette is a cross-platform color palette grid with ability to select a color from a palette. The OnMouseColorPick event is fired when the user clicks onto a color.

Authors

Tom Gregorovic and Werner Pamler

License

Modified LGPL

Usage

Color selection

When a color is selected by clicking with the mouse onto a color box an event OnColorPick is generated; the event gets the rgb value of the picked color as a parameter. Another parameter passes the ShiftState active during the click; usually this identifies the mouse button pressed. If the property ShowSelection is turned on then the picked color is highlighted.

While the mouse is dragged an event OnColorMouseMove is fired. Again, it has the color underneath the mouse cursor as well as the ShiftState as parameters. It can be used to update a color info display on the form.

The time flow when exactly the color is selected is determined by the property PickMode:

  • pmImmediate: The color is selected, and the event is generated, when the mouse button goes down.
  • pmContinuous: The color is selected, and the event is generated, while the mouse moves and when the mouse button goes up.
  • pmDefault: The color is selected when the mouse button goes down, and the event is generated when the mouse button goes up. Both events must occur at the same location. This mode is a left-over from a previous version of the component and should not be used any more.

Palettes

The components supports a series of built-in palettes as determined by the PaletteKind property:

  • pkStandardPalette: the 16 standard color defined by the graphics unit
  • pkExtendedPalette: the same, but extended by the 4 extra colors clMoneyGreen, clSkyBlue, clCream, clMedGray
  • pkSystemPalette: the 25 system colors defined by the graphics unit
  • pkStandardAndSystemPalette: the standard colors plus the system colors
  • pkExtendedAndSystemPalette: the extended colors plus the system colors
  • pkGradientPalette: "all" colors nicely arranged; use GradientSteps to define the horizontal resolution.
  • pkWebSafePalette: a set of web-safe colors as defined by a wikipedia article.
  • pkWebSafePalette2: another set of web-safe colors.

In addition, a custom palette can be loaded from a file by calling the LoadPalette method. The palette files are simple text files according to this example (see also Default.pal in the component folder):

Custom palette example:
    
 $COLS 8
 # sets count of palette grid columns
 
 0,0,0
 # inserts color r,g,b colorname
 # colorname is optional.
 255,255,255 White
 
 $NONE
 # inserts empty palette grid cell
 
 $BLENDWB 128,128,128 3
 # creates color gradient white -> color -> black with specified steps
 # The specified steps are applied to the transitions between "white" and "color"
 # and between "color" and "black", i.e., in total, there are <tt>2*steps+1</tt> color boxes.

Methods and properties for color access

There are several methods and properties to manipulate and query the entries of the used palette:

  • AddColor(AColor: TColor; AColorName: String = ''): adds a new entry to the palette. An optional color name can be provided.
  • DeleteColor(AIndex: Integer): removes the entry with the specified index from the palette
  • ClearColors: removes all colors from the palette.
  • SavePalette(AFileName: String): saves the currently used palette to a palette file which, in turn, can be re-loaded by means of the LoadPalette method already mentioned.
  • Access individual colors by using the Colors[Index] property.
  • ColorCount returns the number of colors in the palette.
  • PickedColor: returns the currently selected color
  • PickedIndex: returns the index of the currently selected color (indexes are counted first along the rows).
  • MouseColor: returns the color of the button underneath the mouse cursor
  • MouseIndex: returns the index of the color underneath the mouse cursor (indexes are counted first along the rows).
  • Colors[AIndex: Integer]: allows to read and write a color at the specified palette index
  • ColorNames[AIndex:Integer]: allows to read and write the name of the color at the specified palette index. If an empty string is written to the ColorNames property then the colorname defined by the graphics unit is used.

Other properties

Layout

  • ButtonHeight: height of the color buttons (in pixels). Is used along with ColumnCount to define the height of the control.
  • ButtonWidth: width of the color buttons (in pixels). Is used along with ColumnCount to define the width of the control.
  • ButtonDistance: distance, in pixels, between the individual color buttons.
  • ColumnCount: Defines how many color buttons are drawn horizontally.

Visual appearance

  • ButtonBorderColor: defines the borderline around a color button. Can be removed by selecting clNone.
  • Color: defines the background color of the component. Note that the background is not visible if <ttButtondistance = 0.
  • ShowSelection: If true a thick border is drawn around the button of the selected color.
  • UseSpacers: If true clNone color entries serve as spacers to arrange groups of colors. If false clNone is shown as a crossed-out button meaning "transparent color".

Hints

  • ShowColorHint: If true a hint popup window is displayed for the color button above which the mouse cursor hovers. The built-in hint text can be modified by means of the OnGetHintText event.
  • The OnGetHintText allows to modify the built-in text used for creating the popup hint.

Demo project

Two demo projects are contained in the folder demo of the component installation directory:

  • GeneralDemo shows application of all the features of TColorPalette.
  • ToolbarDemo adds a ColorPalette to a coolbar/toolar.

Download and installation

  • Download from Lazarus CCR at SourceForge
  • Install the package LazColorPalette in the Lazarus IDE. The ColorPalette icon is added to the Misc component palette page.

Change Log

Version 0.2

  • New features
    • "AddColor", "DeleteColor" etc.
    • Color names
    • Builtin palettes
    • Highlight selected color
    • Color button distance, border color
    • Color hint window
  • Tested on Windows 2000/XP/7/10, and with gtk2 and qt under Linux (Mint 17).

Version 0.1

  • Initial release
  • Tested on Windows XP, and with gtk1 and gtk2 under Linux (Kubuntu 6.06).