BBC BASIC for Windows
IDE and Compiler >> Tools and Utilities >> DDRMs RGB color picker improved
http://bb4w.conforums.com/index.cgi?board=addins&action=display&num=1464699492

DDRMs RGB color picker improved
Post by michael on May 31st, 2016, 12:58pm

This is how open source would work .. kinda.. if it was open source.. And I rarely see open source happen on any forum, even though there are posts on open source.

We can make it faster, better stronger !!

DDRM Is this program open source or public domain?

I had to modify a few controls, as I wanted more control of positioning. I don't know why you had VDU 4 instead of VDU 5.

I also placed the RGB numbers above the color selector so its handy for a user to write down.

I keep wondering if there is a way to directly use the hexadecimal in a color without converting it..

Looking at how COLOUR works, I take it, hexadecimal and the output value from TINT would be useless without conversion.
Even HTML uses R,G,B values, and I can prove this with a simple conversion from a program I made that creates HTML/CSS web pages..


Code:
      MODE 8
      OFF
      c%=FNGetColour
      MOVE 0,150
      PRINT c%
      COLOUR 0,c% AND 255,(c%>>8)AND 255,(c%>>16) AND 255
      GCOL 0
      CIRCLE FILL 200,500,150
      END
      :
      DEFFNGetColour
      LOCAL x%,y%,z%,r%,g%,b%,done%
      done%=FALSE

      REPEAT
        *REFRESH OFF
        GCOL 0
        CLS
        RECTANGLE FILL0,0,400,100
        GCOL 15
        MOVE 0,30
        PRINT"B"
        RECTANGLE 20,10,255,20
        MOVE 0,60
        PRINT"G"
        RECTANGLE 20,40,255,20
        MOVE 0,90
        PRINT"R"
        MOVE 10,120:GCOL 15:PRINT "R: "+STR$(r%)+"    G: "+STR$(g%)+"    B: "+STR$(b%)
        MOVE 0,0
        RECTANGLE 20,70,255,20
        LINE 20+r%,70,20+r%,90
        LINE 20+g%,40,20+g%,60
        LINE 20+b%,10,20+b%,30
        COLOUR 7,r%,g%,b%
        GCOL 7
        RECTANGLE FILL 300,10,80,80
        GCOL 15
        RECTANGLE  390,10,80,80
        MOVE 410,65
        PRINT "OK"
        VDU 5
        MOUSE x%,y%,z%
        IF z%>0 THEN
          CASE TRUE OF
            WHEN y%>9 AND y%<31 AND x%>19 AND x%<276:b%=x%-20
            WHEN y%>39 AND y%<61 AND x%>19 AND x%<276:g%=x%-20
            WHEN y%>69 AND y%<91 AND x%>19 AND x%<276:r%=x%-20
            WHEN y%>10 AND y%<90 AND x%>390 AND x%<470:done%=TRUE
          ENDCASE
        ENDIF
        *REFRESH
      UNTIL done%
      COLOUR 7,200,200,200
      *REFRESH ON
      =(r%+(g%<<8)+(b%<<16))
 

Re: DDRMs RGB color picker improved
Post by DDRM on Jun 6th, 2016, 11:49am

Hi Michael,

Feel free to use any code I post on here as the basis for your own work.

I like the addition of showing the R,G,B values: either at the top as you have done, or maybe next to the slider bars?

In my code I set VDU 5 to tie the text cursor to the graphics cursor, then I released it again with VDU 4 before ending the routine - since that's the default - to reduce the risk of messing up the user's program when the routine returns.

I don't think there's a way of setting the colour using the combined hex value using "standard" BB4W commands, but there is a variable pointing to the palette, so you can set the entry using SetPaletteEntries.

Here's a brief example. The parameters are the handle of the palette, the index of the first colour you want to change, the number of colours you want to change, and a pointer to (an array of) colour numbers. Strictly, these should be PALETTEENTRY structures, including flags in the top byte, but the flags can be 0.
Code:
      r&=200
      g&=100
      b&=0
      col%=(b&<<16)+(g&<<8)+r&
      COLOUR 4,r&,g&,b&
      GCOL 4
      CIRCLE FILL 200,200,200
      GCOL 5
      CIRCLE FILL 500,500,200
      WAIT 100
      SYS "SetPaletteEntries",@hpal%,5,1,^col%
      CIRCLE FILL 500,500,200
 


Best wishes,

D