Sign in Join
Wiki copytemporary

ColorPalette: what changed

Revision 3 to 4. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## About
22
33![ColorPalette](/wiki-images/8/82/ColorPalette.png) 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.
44
55### Authors
66
77Tom Gregorovic and Werner Pamler
88
99### License
1010
1111Modified LGPL
1212
1313## Usage
1414
1515### Color selection
1616
1717When 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.
1818
1919The time flow when exactly the color is selected is determined by the property `PickMode`:
2020
2121- `pmImmediate`: The color is selected, and the event is generated, when the mouse button goes down.
2222- `pmContinuous`: The color is selected, and the event is generated, while the mouse moves and when the mouse button goes up.
2323- `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.
2424
2525### Palettes
2626
2727#### Built-in palettes
2828
2929The components supports a series of **built-in palettes** as determined by the `PaletteKind` property:
3030
3131- `pkStandardPalette`: the 16 standard color defined by the `graphics` unit
3232- `pkExtendedPalette`: the same, but extended by the 4 extra colors `clMoneyGreen, clSkyBlue, clCream, clMedGray`
3333- `pkSystemPalette`: the 25 system colors defined by the `graphics` unit
3434- `pkStandardAndSystemPalette`: the standard colors plus the system colors
3535- `pkExtendedAndSystemPalette`: the extended colors plus the system colors
3636- `pkGradientPalette`: "all" colors nicely arranged; use `GradientSteps` to define the horizontal resolution.
3737- `pkWebSafePalette`: a set of web-safe colors as defined by a [wikipedia article](https://en.wikipedia.org/wiki/Web_colors#Color_table).
3838- `pkWebSafePalette2`: another set of web-safe colors.
3939
4040#### Custom palettes and palette files
4141
4242In 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):
4343
4444 Custom palette example:
4545
4646 $COLS 8
4747 # sets count of palette grid columns
4848
4949 0,0,0
5050 # inserts color r,g,b colorname
5151 # colorname is optional.
5252 255,255,255 White
5353
5454 $NONE
5555 # inserts empty palette grid cell
5656
5757 $BLENDWB 128,128,128 3
5858 # creates color gradient white -> color -> black with specified steps
5959 # The specified steps are applied to the transitions between "white" and "color"
6060 # and between "color" and "black", i.e., in total, there are <tt>2*steps+1</tt> color boxes.
6161
6262A set of **keywords** is defined to identify the palette file entries:
6363
6464- `r,g,b colorname`: Defines the next entry of the color palette by means of its red-green-blue components (0..255). The `colorname` is optional.
6565- `$NONE`: Is a place-holder for an empty color button. Useful for layout optimization. If the property `UseSpacers` is false then the button can be picked as color `clNone`.
6666- `$BLENDBW r,g,b n`: creates a series of palette entries corresponding to a gradient from white to the specified color and to black. Each one of the two gradient consists of `n` steps, i.e. in total, `2*n+1` palette entries are created.
6767- `$COLS value`: defines the number of columns used to display the palette.
6868- `$BTNDIST value`: specifies the pixel distance between the color palette button tiles (`value` is an `integer`)
6969- `$BTNWIDTH value`: specifies the pixel width of each color palette button (`value` is an `integer`)
7070- `$BTNHEIGHT value`: specifies the pixcel height of each color palette button (`value` is an `integer`)
7171- `$BTNBORDER r,g,b`: specifies the color of the border of a palette button in terms of r, g, b values (`0..255`)
7272- `$FLIPPED value`: specifies whether the palette is flipped (`value = TRUE`) or not (`value = FALSE`)
7373- `$SELKIND value`: specifies how the selected palette button is highlighted. `value` can be `NONE`, `THIN`, `THICK`, `THIN-INV`, `THICK-INV`.
7474- `$SELCOLOR r,g,b`: specifies the color with which the selected button is highlighted if `$SELKIND` is `THIN` or `THICK`. The color is given by its red, green and blue components (`0..255`).
7575- `#`: defines a comment - all characters in the same line following the `#` are ignored.
7676
7777### Methods and properties for color access
7878
7979There are several methods and properties to manipulate and query the entries of the used palette:
8080
8181- `AddColor(AColor: TColor; AColorName: String = '')`: adds a new entry to the palette. An optional color name can be provided.
8282- `DeleteColor(AIndex: Integer)`: removes the entry with the specified index from the palette
8383- `ClearColors`: removes all colors from the palette.
8484- `LoadPalette(AFileName: String; AItems: TPaletteItems = [])`: load a palette from specified file. The optional parameter `AItems` allows to define which items stored in the palette are loaded: `TPaletteItems = set of [piColors, piColumnCount, piFlipped, piButtonBorder, piButtonSize, piButtonDistance, piSelKind, piSelColor]`. By default, `AItems` is `[piColors, piColumnCount]` which loads all colors and the column count. Use `piAll` as an abbreviation to load all items.
8585- `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.
8686- Access individual colors by using the `Colors[Index]` property.
8787- `ColorCount` returns the number of colors in the palette.
8888- `PickedColor`: returns the currently selected color
8989- `PickedIndex`: returns the index of the currently selected color (indexes are counted first along the rows).
9090- `MouseColor`: returns the color of the button underneath the mouse cursor
9191- `MouseIndex`: returns the index of the color underneath the mouse cursor (indexes are counted first along the rows).
9292- `Colors[AIndex: Integer]`: allows to read and write a color at the specified palette index
9393- `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.
9494
9595### Other properties
9696
9797#### Layout
9898
9999- `ButtonHeight`: height of the color buttons (in pixels). Is used along with `ColumnCount` to define the height of the control.
100100- `ButtonWidth`: width of the color buttons (in pixels). Is used along with `ColumnCount` to define the width of the control.
101101- `ButtonDistance`: distance, in pixels, between the individual color buttons.
102102- `ColumnCount`: Defines how many color buttons are drawn horizontally.
103103
104104#### Visual appearance
105105
106106- `ButtonBorderColor`: defines the borderline around a color button. Can be removed by selecting `clNone`.
107107- `Color`: defines the background color of the component. Note that the background is not visible if \<ttButtondistance = 0.
108108- `ShowSelection`: If true a thick border is drawn around the button of the selected color.
109109- `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".
110110
111111#### Hints
112112
113113- `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.
114114- The `OnGetHintText` event allows to modify the built-in text used for creating the popup hint.
115115
116116### Demo projects
117117
118118Two demo projects are contained in the folder *demo* of the component installation directory:
119119
120120- **GeneralDemo** shows application of all the features of TColorPalette.
121121- **ToolbarDemo** adds a ColorPalette to a coolbar/toolar.
122122
123123## Download and installation
124124
125-```
125+```text
126126svn checkout https://svn.code.sf.net/p/lazarus-ccr/svn/components/colorpalette
127127```
128128
129129- Download from [Lazarus CCR at SourceForge](http://sourceforge.net/projects/lazarus-ccr/files/ColorPalette/)
130130- Install the package `LazColorPalette` in the Lazarus IDE. The ColorPalette icon is added to the *Misc* component palette page.
131131
132132## Change Log
133133
134134### Version 0.2
135135
136136- **New features**
137137 - "AddColor", "DeleteColor" etc.
138138 - Color names
139139 - Builtin palettes
140140 - Highlight selected color
141141 - Color button distance, border color
142142 - Color hint window
143143 - New keywords in palette file
144144- **Tested** on Windows 2000/XP/7/10, and with gtk2 and qt under Linux (Mint 17).
145145
146146### Version 0.1
147147
148148- **Initial release**
149149- **Tested** on Windows XP, and with gtk1 and gtk2 under Linux (Kubuntu 6.06).
150150
151151---
152152*From the Free Pascal wiki, page "ColorPalette", as it stood on 2016-06-21 after a change by Arent, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
153153Category: Components
154154Category: Graphics
155155Category: Lazarus-CCR

Back to history