B4A Class ColorPalette and CircularPalette

There are many ways to pick a color from within an application, so I contribute another.
You select any possible color in a the color palette, modify the brightness and press ok.
Some subs useful with colors which were used are enabled as functions in the class:
- ParseColor - returns the components of the color
- HSLToRGB
- COLORtoHSL

The class needs the pictures in files.

Edit: ver 1.1, landscape fills the screen.
Edit: Ver. 2.0
Edit: Ver 2.1 limits the cursor movements to the palette.
Edit: ver 2.2 - added the freeze orientation code by stevel05 (Thanks !)
from here http://www.b4x.com/android/forum/threads/freeze-orientation.41681/
Edit: Ver 2.3 with modified code for Freezing the orientation. This may behave wrongly with some devices.

Edit: CircularPalette added as another class. It is very simple and is a color picker, see photo.
 

Attachments

  • cp.png
    cp.png
    102 KB · Views: 989
  • ColorPalette_2.3.zip
    88.9 KB · Views: 765
  • cp.png
    cp.png
    97 KB · Views: 700
  • CircularPalette.zip
    123.4 KB · Views: 732
Last edited:

derez

Expert
Licensed User
Longtime User
Ver. 2.0 - added the JobId so that identification of the result in sub [object]_result can be used.
Better adaptation to various screen sizes.
 

Peter Simpson

Expert
Licensed User
Longtime User
Hello @derez thank you for that.
I searched for color dialog and color picker but I didn't find your colorpalette. Thank you for pointing me to this post.

Anyway, is there a way to stop the 2 cursors from going past the color palette borders. As the cursors go past the borders in portrait and landscape modes, all sorts of colors appear instead of actually stopping on the final border color. The end user will find this frustrating especially if they want to select just black or white.

Have you thought about turning this into a proper dialog box, that would make this 100 times more user friendly. Please do not take my last comment the wrong way, it's just a suggestion for your already really nice colorpalette :)

This is what happens if you pull the cursor past the red on the right of the colour picker box

Screenshot_2014-03-16-14-09-04.jpg


Below you can see that the end user can easily pull the cursors off the screen.

Screenshot_2014-03-16-14-09-37.jpg


Both the above makes for a bad experience for the end user. As you can see above, making the cursors disappear is rather easy :-(

Thank you
 
Last edited:

kohle

Active Member
Licensed User
Longtime User
Hi,

when I use your class on a fone with a higher resolution than the color palette appears less than half screen. (Very small)
 

stanks

Active Member
Licensed User
Longtime User
how to change alpha value? i was searching for color dialogs here but color dialogs here does not show/allow to change alpha value...
 

derez

Expert
Licensed User
Longtime User
stanks asked:
how to change alpha value
Alfa value is not controlled by the color palette.
Alfa value sets the transparency of the color without changing the color itself.
you can define it by code using colors.ARGB, where the first of the four arguments is alfa.
If it is necessary in your application you should add a seekbar to the color palette to set the alfa.
 

Peter Simpson

Expert
Licensed User
Longtime User
hello @derez,
I've only just remembered to come back and look at your colorpalette. I'm pleased that you managed to sort out the small issue that I pointed out to you. I did have a quick look at your code and was going to play about with it go fix the issue, but I though it was better to let you know. That way it would also help others who would like to use your colorpalette.

Thank you :)
 

udg

Expert
Licensed User
Longtime User
Hi derez,
reading you code for version 2.2 I am puzzled by the last statement in sub Initialize.
It calls sub drawlum which has a for/next loop to derive a color as long type from H/S/L parameters.
My question is: where did you set initial values for Hue and Sat variables?

It's my understanding that each call from Main (i.e. using the lib) goes through "common" and so there's a preliminary passage through ColorToHSL that sets those vars, but what about the Initialize sub?

Thank you for a great lib made up of a few gems hard to find elsewhere.

Umberto
 

udg

Expert
Licensed User
Longtime User
Thank you, derez.
I am on vacation too :)

Umberto
 

derez

Expert
Licensed User
Longtime User
Yes. The returned color can be assigned to a view 's textcolor property.
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
Got this running, but for some odd reason the first color pick it's returned. The second pick, flips the screen and seems to work fine.
 

derez

Expert
Licensed User
Longtime User
UDG:
reading you code for version 2.2 I am puzzled by the last statement in sub Initialize.
You are right, calling the darwlum in the initialization is not required. I shall delete it in the next version with the updated code for freezing the orientation.

merlin2049er:
for some odd reason the first color pick it's returned.
You'll have to show me the code you use.
 
Last edited:
Top