1. Black Friday Sale - 50% off

    B4A Standard for $29 instead of $59!
    Buy Now
    Dismiss Notice

B4A Class ColorPalette and CircularPalette

Discussion in 'Additional libraries, classes and official updates' started by derez, Sep 7, 2013.

  1. derez

    derez Expert Licensed User

    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.basic4ppc.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.

    Attached Files:

    Last edited: Dec 26, 2014
  2. derez

    derez Expert Licensed User

    Ver 1.1 - landscape fills the screen.
  3. derez

    derez Expert Licensed 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.
  4. Peter Simpson

    Peter Simpson Expert Licensed 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


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


    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: Mar 16, 2014
  5. derez

    derez Expert Licensed User

    Version 2.1 limits the cursor's movement.
    Thank you Peter for the observation.
    Peter Simpson likes this.
  6. kohle

    kohle Active Member Licensed User


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

    derez Expert Licensed User

    On 1080x1920 it looks ok. What resolution do you use ? are you checking with ver 2.1 ?
    Peter Simpson likes this.
  8. stanks

    stanks Active Member Licensed 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...
  9. derez

    derez Expert Licensed User

    stanks asked:
    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.
  10. Peter Simpson

    Peter Simpson Expert Licensed 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 :)
  11. derez

    derez Expert Licensed User

  12. udg

    udg Expert Licensed 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.

  13. derez

    derez Expert Licensed User

    I'll answer in few days when I'm back from vacation
  14. udg

    udg Expert Licensed User

    Thank you, derez.
    I am on vacation too :)

  15. merlin2049er

    merlin2049er Well-Known Member Licensed User

    Nice lib, can you use this to set font colors?
  16. derez

    derez Expert Licensed User

    Yes. The returned color can be assigned to a view 's textcolor property.
  17. merlin2049er

    merlin2049er Well-Known Member Licensed 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.
  18. derez

    derez Expert Licensed User

    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.

    You'll have to show me the code you use.
    Last edited: Oct 16, 2014
  19. derez

    derez Expert Licensed User

  20. derez

    derez Expert Licensed User

    CircularPalette class added
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice