Hi,
I did some things, and now it's on Github. Feel free to look: https://github.com/Trashtalk217/ltk-colorpicker.
Thanks for the advice I got. I now use two images for displaying the color wheel and the white-to-black gradient. While most of the code is still yanky as heck (just look at my installation instructions -_-). I've managed to create something that works, which I'm very happy with. And although the color wheel doesn't become darker when you turn down the brightness, I don't necessarily need it. I can do fine without.
Edgar noted that there's a lisp variable which controls if the Tk code gets printed out to standard output, but they didn't know which one it was. I found it: (setf *debug-tk* t). I've barely used it because Tk hasn't particularly the nicest syntax, but I know where it is if I need it.
Otherwise, thanks again for the help, and I hope you all have a great day.
Greetings, Tom
On 8/15/19 10:41 AM, cage wrote:
On Wed, Aug 14, 2019 at 08:49:30PM +0200, Tom wrote:
Hi,
Hello!
I'm back from vacation and continuing my exploration of ltk.
Hope you had fun! :)
I'm currently trying to build a color picker
i think this is an exercise (and a good one in my opinion) otherwise please consider using:
https://www.tcl.tk/man/tcl8.6/TkCmd/chooseColor.htm
and I'm modeling it after the blender color picker. To replicate how it looks I need a nice gradient. My first instinct was to just put a bunch of really small rectangles (pixels) on a canvas. This worked (see attachment), but it took about 5 minutes for all the pixels to be put on the canvas. Not ideal,
Yes, canvas is slow for these operations.
especially if I have to redraw the gradient when the brightness value is changed by some slider or something. My next idea was to use a bitmap. This leads my to my first question: How do I get a bitmap on a canvas? I tried the following code.
Please note that 'bitmap' is for 1 bit color depth image (i e. two color) plus a transparency binary value, according to the documentation:
https://www.tcl.tk/man/tcl8.6/TkCmd/bitmap.htm
Moreover the format the library accepts is not MS bitmap but X11 bitmap format, never used but likely these are the specification (please someone correct if i am wrong):
https://en.wikipedia.org/wiki/X_BitMap
What i think you need is a photo-image:
https://www.tcl.tk/man/tcl8.6/TkCmd/photo.htm
that, instead support 24bit (plus alpha in the upcoming 8.7 release of tcl/tk) color depth image.
Tk supports only PNG and GIF format (you can write your own loader but this is a more complicate task, so i will stick to PNG here):
(with-ltk () (let ((canvas (make-canvas nil :width 64 :height 64)) (image (make-image))) (image-load image "/path/to/a/file/in/png/format.png") (create-image canvas 0 0 :image image) (pack canvas)))
There is really no example given in the documentation. So I need help with this one (Using SBCL on Linux by the way).
The next question is concerning transparent colors. To darken the gradient I thought of having an oval over the bitmap, on which I can change the transparency value. I haven't found a way to do that with "itemconfigure". And I also haven't found a place where all the keyword arguments are listed for "itemconfigure".
I suggest to look at the ltk sources and the official tk documentation.
https://www.tcl.tk/man/tcl8.6/TkCmd/canvas.htm
IIRC usually the options that 'ltk:itemconfigure' accepts are the same that 'ltk:create-*' accepts.
I'm almost certain that there are no transparency options for canvas items in tcl/tk. But in case I've overlooked them, I'm asking anyway.
As far as i know there is not an alpha channel but probably you could just do the calculation for transparency value outside and draw the oval with the results color (in this case could be useful to look at ltk:image-setpixel); this, also, could be a tedious and complex task to accomplish, though.
I'd also like to say that I accept tips on my approach. Is there an obvious solution that I'm missing or are there other general tips I need to figure it out myself. Please let me know! Thanks in advance for any help.
Well the best i can suggest is to take a look here :-)
https://github.com/VitoVan/cl-pkr
Bye, and happy hacking! :)
C.
PS: annoying legal stuff: all my code in this message is released under MIT license https://opensource.org/licenses/MIT