Recent

Author Topic: TColorPalette...  (Read 19142 times)

polpero

  • Jr. Member
  • **
  • Posts: 72
TColorPalette...
« on: August 19, 2015, 01:01:58 pm »
Hi

Has anyone experimented with TColorPalette?

I'm looking for examples of picking a color on the palette, adding colors, saving and loading a palette etc...

I'm on windows8 but it shouldn't matter here it think

thanks!

wp

  • Hero Member
  • *****
  • Posts: 6485
Re: TColorPalette...
« Reply #1 on: August 19, 2015, 01:23:55 pm »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

polpero

  • Jr. Member
  • **
  • Posts: 72
Re: TColorPalette...
« Reply #2 on: August 19, 2015, 02:20:50 pm »
yes i know this page

thanks

but it's not really an example
those lines are also in the source code of the component
and couldn't serve as usage example as asked previously

thanks anyway

Graeme

  • Hero Member
  • *****
  • Posts: 1430
    • Graeme on the web
Re: TColorPalette...
« Reply #3 on: August 19, 2015, 03:08:32 pm »
... adding colors, saving and loading a palette etc...
I've never used that component, but looking at the code, you load a new palette by calling LoadPalette(AFilename). Custom palette colours are defined in an external file [I think that's a strange design choice]. The code supplies such an example in the file default.pal. Hope that helps.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

wp

  • Hero Member
  • *****
  • Posts: 6485
Re: TColorPalette...
« Reply #4 on: August 19, 2015, 04:29:07 pm »
I added a demo project showing the main usage of the component. Since, as Graeme mentioned, defining colors by means of a file is really not the most versatile way I added two methods, "AddColor(AColor: TColor)" and "DeleteColor(AIndex: Integer") as well as a property "ColorCount" for better handling of the colors. There is a new method "SavePalette" for writing the modified palette to a file compatible with "LoadPalette". Finally, there is also a new "ColumnCount" property.

All these new features are covered in the demo as well. You'll need svn to get access to these changes in TColorPalette (r4275).

I hope the original author of the component does not object against me hijacking his project in CCR, but his last contributions in the forum date back to 2008, and therefore I thought a standard bug report would just be a waist of time.
« Last Edit: August 19, 2015, 05:11:41 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

polpero

  • Jr. Member
  • **
  • Posts: 72
Re: TColorPalette...
« Reply #5 on: August 19, 2015, 06:24:50 pm »
Exactly...

those is where the points i was addressing (adding col, loading and saving palette, colors count)

thanks i'll have a look at your demo

polpero

  • Jr. Member
  • **
  • Posts: 72
Re: TColorPalette...
« Reply #6 on: August 20, 2015, 03:34:25 pm »
wp

Thanks for the demo
i've been exploring and updating it a bit...

using a curColorIndex integer, i added a few utilities
  • delete colors[curIndex]
  • edit curcolor
  • update palette
  • and a TShape showing the pickedColor

I wonder if that colorIndex shoudn't be at the component's level ?

any way the new demo is here as attachment (PaletteDemo.zip)



wp

  • Hero Member
  • *****
  • Posts: 6485
Re: TColorPalette...
« Reply #7 on: August 20, 2015, 05:00:01 pm »
One thing is confusing with the component: If I press the left mouse button down and move the mouse by a few pixels (as it can easily happen) then the ColorPick event does not fire. This is because in "MouseUp" there is a check against the original mouse-down position. This seems to be necessary because the picked color is calculated in "MouseDown", and it would be confusing if the user moves the mouse into a neighboring square and does not get the color underneath the mouse at mouse-up.

To me personally, this behavior is a bit confusing. The component would feel more practical if the ColorPick would occur at "MouseDown"; in MouseMove, there could be code to track the PickedColor.

To keep the old behavior I could add a new enumerated property, something like "PickEvent": TPickEvent = (peMouseDown, peMouseMove, peMouseUp). The current behavior corresponds to peMouseDown which should be the default to avoid breaking existing projects. peMousedown would allow dragging the mouse across the palette - the color box in your demo would immediately respond while dragging. peMouseUp picks the color from the position where the mouse button is released.

Polpero, since you seem to be the only person working with the TColorPalette, what is your opinion?
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

polpero

  • Jr. Member
  • **
  • Posts: 72
Re: TColorPalette...
« Reply #8 on: August 20, 2015, 07:46:26 pm »
wp
Your suggestion looks good.

It doesn't seem to break what is already there
and might help using popupmenus
(i had trouble trying to put the updatePalette in it
  as it erased the previous editColor operation )

wp

  • Hero Member
  • *****
  • Posts: 6485
Re: TColorPalette...
« Reply #9 on: August 20, 2015, 11:12:21 pm »
There's a new version in svn with new properties "PickMode" and "PickShift":

PickMode:
- pmDefault (default value): current behavior, i.e. color is selected from the square in which MouseDown occurs, but the OnPickColor event fires later when the mouse is released, but only if this happens at the same location.
- pmImproved: color is selected at MouseDown, and OnPickColor fires also at this time; location can be different
- pmContinuous: color selection and event generation occur while the mouse button is down; the mouse can be dragged.

PickShift:
a set with the TShiftState elements ssLeft, ssRight and ssMiddle to define the mouse buttons to which the ColorPalette reacts. Default is ssLeft. If a context menu is used like in the demo then it is advantageous to add ssRight to the set as well.

@polpero: I uploaded your modified demo.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

wp

  • Hero Member
  • *****
  • Posts: 6485
Re: TColorPalette...
« Reply #10 on: August 21, 2015, 05:34:27 pm »
A couple of new changes:
  • The component does bookkeeping of the selected color index itself now (property SelectedIndex), no need for a "curIndex" in the application any more.
  • OnColorPick has been reverted to no longer check for the correct shift state, and behaves now just like in the original version again.
  • New event OnSelectColor which is the same as OnColorPick, but checks whether the shiftstate matches on of the TPickShift states.
  • Popup hints showing information on the color over which the mouse hovers.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

polpero

  • Jr. Member
  • **
  • Posts: 72
Re: TColorPalette...
« Reply #11 on: August 21, 2015, 07:00:23 pm »
Great!

I'm working on implementing three other properties
reading your code i thought i'd be better to share before:

i want a fShowGrid (boolean) property
which when true activates fGridColor (TColor) the grid color
and fGridWidth (integer) the canvas.pen.size

what do you think of it?

what confuses me a bit is your insertion of
Code: [Select]
if FShowSelection and (FSelectedIndex = I) in the Paint event, that seem to take the place i thought for if fShowGrid...

what do you think?




 

wp

  • Hero Member
  • *****
  • Posts: 6485
Re: TColorPalette...
« Reply #12 on: August 21, 2015, 07:21:20 pm »
With "grid" you mean the border of the color boxes? This is currently on. To turn it off we could replace in the Paint method the "Canvas.Rectangle" by a "Canvas.FillRect" which does not paint the border. The color and line width of the border are determined by the pen of the canvas - normally they are "clBlack" and "1". If the currently selected color is drawn (that's the "if" you mention) then I though it would be good to increase the line width to 3 and to select a high-contrast opposite color - white border for "dark" colors, black border for "bright" colors.

Or do you want a gap between the boxes, like in Delphi's TColorGrid? In this case, it would also be possible to paint a sunken 3d frame around the color boxes. But how to highlight the selected color? By means of a raised box?
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

polpero

  • Jr. Member
  • **
  • Posts: 72
Re: TColorPalette...
« Reply #13 on: August 21, 2015, 08:37:08 pm »
Yes
the grid is the boxe's borders...

in the test i've done i painted all in fill rect to wich a rect was over 'drawn' when grid was on... I effectively think it more as a gap (especially when grid is off) ... see attachment
 
i wasn't too much concerned about the selected box. Although i'd prefer the 'flat' look, it could be an option... The "focusCell" would really stand out in the gridless mode...


wp

  • Hero Member
  • *****
  • Posts: 6485
Re: TColorPalette...
« Reply #14 on: August 22, 2015, 12:33:54 am »
Now with BorderColor and BorderWidth.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10