Author Topic: Color Dialog  (Read 4661 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Color Dialog
« on: June 21, 2019, 12:49:32 pm »
OK what did I forget?
Code: QB64: [Select]
  1. _TITLE "Color Dialog" 'started by B+ 2019-06-21
  2.  
  3. 'from :"Color CONST for _RGBA32(red, green, blue, alpha)" 'B+ 2019-05-19
  4. '2019-05-26 update this for mouse inputs
  5. '>>>>>>>>>>>> test your colors here
  6. '>>>>>>>>>>>> then create and name Hex string CONSTs if you want to the Clipboard
  7. 'sample clipping
  8. CONST Purple = &HFFB400B4
  9. ' 2019-06-21 start color dialog
  10.  
  11. SCREEN _NEWIMAGE(1200, 700, 32)
  12. _SCREENMOVE 100, 20
  13. COLOR &HFF0000BB, &HFFAAAAAA
  14. FOR i = 1 TO 150
  15.     LINE (RND * 1200, RND * 700)-STEP(RND * 50, RND * 50), _RGB32(RND * 255, RND * 255, RND * 255), BF
  16. PRINT "in 4 secs Color Dialog comes up..."
  17. colorDialog rc
  18. PRINT "Color Dialog returned this:"; rc
  19. IF rc <> 0 THEN LINE (100, 100)-STEP(1000, 500), rc, BF
  20. PRINT: PRINT "End of Color Dialog test..."
  21.  
  22. SUB colorDialog (returnColor AS _UNSIGNED LONG)
  23.  
  24.     'first screen dimensions items to restore at exit
  25.     DIM curRow AS INTEGER, curCol AS INTEGER, autoDisplay AS INTEGER
  26.     DIM curScrn AS LONG, backScrn AS LONG 'some handles
  27.  
  28.     DIM cd AS LONG
  29.     DIM makeConst$, k$
  30.  
  31.     'save old settings to restore at end ofsub
  32.     curRow = CSRLIN
  33.     curCol = POS(0)
  34.     autoDisplay = _AUTODISPLAY
  35.     sw = _WIDTH
  36.     sh = _HEIGHT
  37.     fg = _DEFAULTCOLOR
  38.     bg = _BACKGROUNDCOLOR
  39.     _KEYCLEAR
  40.     'screen snapshot
  41.     curScrn = _DEST
  42.     backScrn = _NEWIMAGE(sw, sh, 32)
  43.     _PUTIMAGE , curScrn, backScrn
  44.  
  45.     cd = _NEWIMAGE(800, 600, 32)
  46.     SCREEN cd
  47.     r = 128: g = 128: b = 128: a = 128
  48.     COLOR &HFFDDDDDD, 0
  49.     DO
  50.         CLS
  51.         makeConst$ = "&H" + RIGHT$(STRING$(8, "0") + HEX$(_RGBA32(r, g, b, a)), 8)
  52.         slider 16, 10, r, "Red"
  53.         slider 16, 60, g, "Green"
  54.         slider 16, 110, b, "Blue"
  55.         slider 16, 160, a, "Alpha"
  56.         _PRINTSTRING (150, 260), "Press enter or spacenbar, if you want to use the color: " + makeConst$
  57.         _PRINTSTRING (210, 280), "Press escape or q, to not use any color, returns 0."
  58.         LINE (90, 300)-(710, 590), , B
  59.         LINE (100, 310)-(700, 580), VAL(makeConst$), BF
  60.  
  61.         WHILE _MOUSEINPUT: WEND
  62.         mb = _MOUSEBUTTON(1)
  63.         IF mb THEN 'clear it
  64.             mx = _MOUSEX: my = _MOUSEY
  65.             IF mx >= 16 AND mx <= 784 THEN
  66.                 IF my >= 10 AND my <= 50 THEN
  67.                     r = _ROUND((mx - 16) / 3)
  68.                 ELSEIF my >= 60 AND my <= 100 THEN
  69.                     g = _ROUND((mx - 16) / 3)
  70.                 ELSEIF my >= 110 AND my <= 150 THEN
  71.                     b = _ROUND((mx - 16) / 3)
  72.                 ELSEIF my >= 160 AND my <= 200 THEN
  73.                     a = _ROUND((mx - 16) / 3)
  74.                 END IF
  75.             END IF
  76.         END IF
  77.         k$ = INKEY$
  78.         IF LEN(k$) THEN
  79.             IF ASC(k$) = 27 OR k$ = "q" THEN returnColor = 0: EXIT DO
  80.             IF ASC(k$) = 13 OR k$ = " " THEN returnColor = _RGBA32(r, g, b, a): EXIT DO
  81.         END IF
  82.         _DISPLAY
  83.         _LIMIT 60
  84.     LOOP
  85.  
  86.     'put things back
  87.     SCREEN curScrn
  88.     COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0): CLS
  89.     _PUTIMAGE , backScrn
  90.     _DISPLAY
  91.     COLOR fg, bg
  92.     _FREEIMAGE backScrn
  93.     _FREEIMAGE cd
  94.     IF autoDisplay THEN _AUTODISPLAY
  95.     'clear key presses
  96.     _KEYCLEAR
  97.     'clear mouse clicks
  98.     mb = _MOUSEBUTTON(1)
  99.     IF mb THEN 'clear it
  100.         WHILE mb 'OK!
  101.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  102.             _LIMIT 10
  103.         WEND
  104.     END IF
  105.     LOCATE curRow, curCol
  106.  
  107.  
  108. SUB slider (x, y, value, label$)
  109.     DIM c~&, s$
  110.     SELECT CASE label$
  111.         CASE "Red": c~& = &HFFFF0000
  112.         CASE "Green": c~& = &HFF008800
  113.         CASE "Blue": c~& = &HFF0000FF
  114.         CASE "Alpha": c~& = &H88FFFFFF
  115.     END SELECT
  116.     LINE (x, y)-STEP(768, 40), c~&, B
  117.     LINE (x, y)-STEP(3 * value, 40), c~&, BF
  118.     s$ = label$ + " = " + _TRIM$(STR$(value))
  119.     _PRINTSTRING (x + 384 - 4 * LEN(s$), y + 12), s$
  120.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Color Dialog
« Reply #1 on: June 21, 2019, 01:21:53 pm »
Hi BPlus, do you remember that Alpha changes color depending on the background color? This means that the resulting color will always be of a different appearance but of the same value if you add a different screen clearing color than black to the CLS command on row 57?

This assumes that you apply the obtained value as a color number to different commands. Then there will be color mixing (for alpha < 255) depending on the background. The only way in which background color mixing does not occur is to insert colors into the image directly with the MEM command.
scrimage.JPG
* scrimage.JPG (Filesize: 108.45 KB, Dimensions: 1640x634, Views: 197)
« Last Edit: June 21, 2019, 01:33:34 pm by Petr »

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Color Dialog
« Reply #2 on: June 21, 2019, 01:34:58 pm »
What a handy little Color Mix Decoder for want of something more descriptive. I don't exactly follow what Petr is pointing out. I do see where, if I set the Alpha to zero there is no color whatever the RBG settings, and with Alpha at it's highest level, color mixes seem more vibrant. I normally work with adding color on a black background, is Petr saying the color mix this program provides ONLY works on a black background?

Thanks bplus - was handy hexidecimeter.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Color Dialog
« Reply #3 on: June 21, 2019, 01:52:16 pm »
Here I solved it. Fellippe explained it to me. https://www.qb64.org/forum/index.php?topic=1325.0

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Color Dialog
« Reply #4 on: June 21, 2019, 02:10:38 pm »
Hi,

I think what Petr is concerned about is that if I lay a transparent color over another color and then take a POINT reading of that color value, the POINT will return Neither the transparent color value Nor the original color value that it overlaid. POINT will return some blend of those two numbers.

Petr's point gives me the idea to show a range of colors for background, so that one can see how the transparent or even the solid colors being tested compare to other colors side by side.

Correct me please if I am wrong.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Color Dialog
« Reply #5 on: June 21, 2019, 02:17:46 pm »
Oh, also which would be better to return: the Hexidecimal$ which a FUNCTION can return or the _UNSIGNED LONG value that _RGBA() function gives us which, I think, we can't return with FUNCTIONs (hence my use of a SUB)?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Color Dialog
« Reply #6 on: June 21, 2019, 02:30:50 pm »
I don't understand exactly your question. Both the SUB and the FUNCTION can return an unsigned long value. Just use ~& in function name, something as FUNCTION GETCOLOR~& to return these values, for SUB, follow these steps:

DIM c AS _UNSIGNED LONG
GetColor c~&
PRINT _ALPHA32(c~&), _RED32(c~&), _GREEN32(c~&), _BLUE32(c~&)


SUB GetColor (OutColor AS _UNSIGNED LONG)
    OutColor~& = &HFFFF0000
END SUB

Quote
Petr's point gives me the idea to show a range of colors for background, so that one can see how the transparent or even the solid colors being tested compare to other colors side by side.

I am curious to the way you want to do it. Perhaps it would be if the user set a background color where he apply a new color... but how do you do this in case, for example, a partially transparent rectangle will paint over many different colors?

« Last Edit: June 21, 2019, 02:45:32 pm by Petr »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Color Dialog
« Reply #7 on: June 21, 2019, 03:12:54 pm »
Quote
Both the SUB and the FUNCTION can return an unsigned long value. Just use ~& in function name, something as FUNCTION GETCOLOR~& to return these values, for SUB, follow these steps:

Right, there was some reason I did not like or did not want ~& at the end of a function name...

Here is mod that returns the Hex$ and shows what the color looks like laid over a host of color!
To use the hex$ value just apply VAL(hex$):
Code: QB64: [Select]
  1. _TITLE "Color Dialog" 'started by B+ 2019-06-21
  2.  
  3. 'from :"Color CONST for _RGBA32(red, green, blue, alpha)" 'B+ 2019-05-19
  4. '2019-05-26 update this for mouse inputs
  5. '>>>>>>>>>>>> test your colors here
  6. '>>>>>>>>>>>> then create and name Hex string CONSTs if you want to the Clipboard
  7. 'sample clipping
  8. CONST Purple = &HFFB400B4
  9. ' 2019-06-21 start Color Dialog
  10.  
  11. SCREEN _NEWIMAGE(1200, 700, 32)
  12. _SCREENMOVE 100, 20
  13. DIM rc$, i
  14. COLOR &HFF0000BB, &HFFAAAAAA
  15. FOR i = 1 TO 150
  16.     LINE (RND * 1200, RND * 700)-STEP(RND * 150, RND * 150), _RGBA32(RND * 256, RND * 256, RND * 256, RND * 256), BF
  17. PRINT "in 4 secs Color Dialog comes up..."
  18. rc$ = colorDialog$
  19. PRINT "Color Dialog returned this:"; rc$
  20. IF rc$ <> "" THEN LINE (100, 100)-STEP(1000, 500), VAL(rc$), BF
  21. PRINT: PRINT "End of Color Dialog test..."
  22.  
  23. FUNCTION colorDialog$
  24.  
  25.     'first screen dimensions items to restore at exit
  26.     DIM curRow AS INTEGER, curCol AS INTEGER, autoDisplay AS INTEGER
  27.     DIM curScrn AS LONG, backScrn AS LONG 'some handles
  28.  
  29.     DIM cd AS LONG
  30.     DIM makeConst$, k$
  31.     DIM f AS SINGLE
  32.  
  33.     'save old settings to restore at end ofsub
  34.     curRow = CSRLIN
  35.     curCol = POS(0)
  36.     autoDisplay = _AUTODISPLAY
  37.     sw = _WIDTH
  38.     sh = _HEIGHT
  39.     fg = _DEFAULTCOLOR
  40.     bg = _BACKGROUNDCOLOR
  41.     _KEYCLEAR
  42.     'screen snapshot
  43.     curScrn = _DEST
  44.     backScrn = _NEWIMAGE(sw, sh, 32)
  45.     _PUTIMAGE , curScrn, backScrn
  46.  
  47.     cd = _NEWIMAGE(800, 600, 32)
  48.     SCREEN cd
  49.     r = 128: g = 128: b = 128: a = 128
  50.     COLOR &HFFDDDDDD, 0
  51.     DO
  52.         CLS
  53.         makeConst$ = "&H" + RIGHT$(STRING$(8, "0") + HEX$(_RGBA32(r, g, b, a)), 8)
  54.         slider 16, 10, r, "Red"
  55.         slider 16, 60, g, "Green"
  56.         slider 16, 110, b, "Blue"
  57.         slider 16, 160, a, "Alpha"
  58.         _PRINTSTRING (150, 260), "Press enter or spacenbar, if you want to use the color: " + makeConst$
  59.         _PRINTSTRING (210, 280), "Press escape or q, to not use any color, returns 0."
  60.         LINE (90, 300)-(710, 590), , B
  61.         FOR i = 100 TO 700
  62.             f = 255 * (i - 100) / 600
  63.             LINE (i, 310)-STEP(0, 30), _RGB32(f, 0, 0)
  64.             LINE (i, 340)-STEP(0, 30), _RGB32(0, f, 0)
  65.             LINE (i, 370)-STEP(0, 30), _RGB32(0, 0, f)
  66.             LINE (i, 400)-STEP(0, 30), _RGB32(f, f, 0)
  67.             LINE (i, 430)-STEP(0, 30), _RGB32(0, f, f)
  68.             LINE (i, 460)-STEP(0, 30), _RGB32(f, 0, f)
  69.             LINE (i, 490)-STEP(0, 30), _RGB32(f, f, f)
  70.             LINE (i, 520)-STEP(0, 30), _RGB32(0, 0, 0)
  71.             LINE (i, 550)-STEP(0, 30), _RGB32(255, 255, 255)
  72.         NEXT
  73.         LINE (100, 310)-(700, 580), VAL(makeConst$), BF
  74.         WHILE _MOUSEINPUT: WEND
  75.         mb = _MOUSEBUTTON(1)
  76.         IF mb THEN 'clear it
  77.             mx = _MOUSEX: my = _MOUSEY
  78.             IF mx >= 16 AND mx <= 781 THEN
  79.                 IF my >= 10 AND my <= 50 THEN
  80.                     r = INT((mx - 16) / 3)
  81.                 ELSEIF my >= 60 AND my <= 100 THEN
  82.                     g = INT((mx - 16) / 3)
  83.                 ELSEIF my >= 110 AND my <= 150 THEN
  84.                     b = INT((mx - 16) / 3)
  85.                 ELSEIF my >= 160 AND my <= 200 THEN
  86.                     a = INT((mx - 16) / 3)
  87.                 END IF
  88.             END IF
  89.         END IF
  90.         k$ = INKEY$
  91.         IF LEN(k$) THEN
  92.             IF ASC(k$) = 27 OR k$ = "q" THEN EXIT DO
  93.             IF ASC(k$) = 13 OR k$ = " " THEN colorDialog$ = makeConst$: EXIT DO
  94.         END IF
  95.         _DISPLAY
  96.         _LIMIT 60
  97.     LOOP
  98.  
  99.     'put things back
  100.     SCREEN curScrn
  101.     COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0): CLS
  102.     _PUTIMAGE , backScrn
  103.     _DISPLAY
  104.     COLOR fg, bg
  105.     _FREEIMAGE backScrn
  106.     _FREEIMAGE cd
  107.     IF autoDisplay THEN _AUTODISPLAY
  108.     'clear key presses
  109.     _KEYCLEAR
  110.     'clear mouse clicks
  111.     mb = _MOUSEBUTTON(1)
  112.     IF mb THEN 'clear it
  113.         WHILE mb 'OK!
  114.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  115.             _LIMIT 10
  116.         WEND
  117.     END IF
  118.     LOCATE curRow, curCol
  119.  
  120.  
  121. SUB slider (x, y, value, label$)
  122.     DIM c~&, s$
  123.     SELECT CASE label$
  124.         CASE "Red": c~& = &HFFFF0000
  125.         CASE "Green": c~& = &HFF008800
  126.         CASE "Blue": c~& = &HFF0000FF
  127.         CASE "Alpha": c~& = &H88FFFFFF
  128.     END SELECT
  129.     LINE (x, y)-STEP(765, 40), c~&, B
  130.     LINE (x, y)-STEP(3 * value, 40), c~&, BF
  131.     s$ = label$ + " = " + _TRIM$(STR$(value))
  132.     _PRINTSTRING (x + 384 - 4 * LEN(s$), y + 12), s$
  133.  

 
Color Dialog with assorted Backgrounds.PNG


Well the solid colors will just be one solid block... :)
Oh wait... got another idea :)
« Last Edit: June 21, 2019, 03:21:05 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Color Dialog
« Reply #8 on: June 21, 2019, 03:37:12 pm »
Side by side and overlay:
Code: QB64: [Select]
  1. _TITLE "Color Dialog" 'started by B+ 2019-06-21
  2.  
  3. 'from :"Color CONST for _RGBA32(red, green, blue, alpha)" 'B+ 2019-05-19
  4. '2019-05-26 update this for mouse inputs
  5. '>>>>>>>>>>>> test your colors here
  6. '>>>>>>>>>>>> then create and name Hex string CONSTs if you want to the Clipboard
  7. 'sample clipping
  8. CONST Purple = &HFFB400B4
  9. ' 2019-06-21 start Color Dialog
  10.  
  11. SCREEN _NEWIMAGE(1200, 700, 32)
  12. _SCREENMOVE 100, 20
  13. DIM rc$, i
  14. COLOR &HFF0000BB, &HFFAAAAAA
  15. FOR i = 1 TO 150
  16.     LINE (RND * 1200, RND * 700)-STEP(RND * 150, RND * 150), _RGBA32(RND * 256, RND * 256, RND * 256, RND * 256), BF
  17. PRINT "in 4 secs Color Dialog comes up..."
  18. rc$ = colorDialog$
  19. PRINT "Color Dialog returned this:"; rc$
  20. IF rc$ <> "" THEN LINE (100, 100)-STEP(1000, 500), VAL(rc$), BF
  21. PRINT: PRINT "End of Color Dialog test..."
  22.  
  23. FUNCTION colorDialog$
  24.  
  25.     'first screen dimensions items to restore at exit
  26.     DIM curRow AS INTEGER, curCol AS INTEGER, autoDisplay AS INTEGER
  27.     DIM curScrn AS LONG, backScrn AS LONG 'some handles
  28.  
  29.     DIM cd AS LONG
  30.     DIM makeConst$, k$
  31.     DIM f AS SINGLE
  32.  
  33.     'save old settings to restore at end ofsub
  34.     curRow = CSRLIN
  35.     curCol = POS(0)
  36.     autoDisplay = _AUTODISPLAY
  37.     sw = _WIDTH
  38.     sh = _HEIGHT
  39.     fg = _DEFAULTCOLOR
  40.     bg = _BACKGROUNDCOLOR
  41.     _KEYCLEAR
  42.     'screen snapshot
  43.     curScrn = _DEST
  44.     backScrn = _NEWIMAGE(sw, sh, 32)
  45.     _PUTIMAGE , curScrn, backScrn
  46.  
  47.     cd = _NEWIMAGE(800, 600, 32)
  48.     SCREEN cd
  49.     r = 128: g = 128: b = 128: a = 128
  50.     COLOR &HFFDDDDDD, 0
  51.     DO
  52.         CLS
  53.         makeConst$ = "&H" + RIGHT$(STRING$(8, "0") + HEX$(_RGBA32(r, g, b, a)), 8)
  54.         slider 16, 10, r, "Red"
  55.         slider 16, 60, g, "Green"
  56.         slider 16, 110, b, "Blue"
  57.         slider 16, 160, a, "Alpha"
  58.         _PRINTSTRING (150, 260), "Press enter or spacenbar, if you want to use the color: " + makeConst$
  59.         _PRINTSTRING (210, 280), "Press escape or q, to not use any color, returns 0."
  60.         LINE (90, 300)-(710, 590), , B
  61.         FOR i = 100 TO 700
  62.             f = 255 * (i - 100) / 600
  63.             LINE (i, 310)-STEP(0, 30), _RGB32(f, 0, 0): LINE (i, 310)-STEP(0, 20), VAL(makeConst$)
  64.             LINE (i, 340)-STEP(0, 30), _RGB32(0, f, 0): LINE (i, 340)-STEP(0, 20), VAL(makeConst$)
  65.             LINE (i, 370)-STEP(0, 30), _RGB32(0, 0, f): LINE (i, 370)-STEP(0, 20), VAL(makeConst$)
  66.             LINE (i, 400)-STEP(0, 30), _RGB32(f, f, 0): LINE (i, 400)-STEP(0, 20), VAL(makeConst$)
  67.             LINE (i, 430)-STEP(0, 30), _RGB32(0, f, f): LINE (i, 430)-STEP(0, 20), VAL(makeConst$)
  68.             LINE (i, 460)-STEP(0, 30), _RGB32(f, 0, f): LINE (i, 460)-STEP(0, 20), VAL(makeConst$)
  69.             LINE (i, 490)-STEP(0, 30), _RGB32(f, f, f): LINE (i, 490)-STEP(0, 20), VAL(makeConst$)
  70.             LINE (i, 520)-STEP(0, 30), _RGB32(0, 0, 0): LINE (i, 520)-STEP(0, 20), VAL(makeConst$)
  71.             LINE (i, 550)-STEP(0, 30), _RGB32(255, 255, 255): LINE (i, 550)-STEP(0, 20), VAL(makeConst$)
  72.         NEXT
  73.         WHILE _MOUSEINPUT: WEND
  74.         mb = _MOUSEBUTTON(1)
  75.         IF mb THEN 'clear it
  76.             mx = _MOUSEX: my = _MOUSEY
  77.             IF mx >= 16 AND mx <= 781 THEN
  78.                 IF my >= 10 AND my <= 50 THEN
  79.                     r = INT((mx - 16) / 3)
  80.                 ELSEIF my >= 60 AND my <= 100 THEN
  81.                     g = INT((mx - 16) / 3)
  82.                 ELSEIF my >= 110 AND my <= 150 THEN
  83.                     b = INT((mx - 16) / 3)
  84.                 ELSEIF my >= 160 AND my <= 200 THEN
  85.                     a = INT((mx - 16) / 3)
  86.                 END IF
  87.             END IF
  88.         END IF
  89.         k$ = INKEY$
  90.         IF LEN(k$) THEN
  91.             IF ASC(k$) = 27 OR k$ = "q" THEN EXIT DO
  92.             IF ASC(k$) = 13 OR k$ = " " THEN colorDialog$ = makeConst$: EXIT DO
  93.         END IF
  94.         _DISPLAY
  95.         _LIMIT 60
  96.     LOOP
  97.  
  98.     'put things back
  99.     SCREEN curScrn
  100.     COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0): CLS
  101.     _PUTIMAGE , backScrn
  102.     _DISPLAY
  103.     COLOR fg, bg
  104.     _FREEIMAGE backScrn
  105.     _FREEIMAGE cd
  106.     IF autoDisplay THEN _AUTODISPLAY
  107.     'clear key presses
  108.     _KEYCLEAR
  109.     'clear mouse clicks
  110.     mb = _MOUSEBUTTON(1)
  111.     IF mb THEN 'clear it
  112.         WHILE mb 'OK!
  113.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  114.             _LIMIT 10
  115.         WEND
  116.     END IF
  117.     LOCATE curRow, curCol
  118.  
  119.  
  120. SUB slider (x, y, value, label$)
  121.     DIM c~&, s$
  122.     SELECT CASE label$
  123.         CASE "Red": c~& = &HFFFF0000
  124.         CASE "Green": c~& = &HFF008800
  125.         CASE "Blue": c~& = &HFF0000FF
  126.         CASE "Alpha": c~& = &H88FFFFFF
  127.     END SELECT
  128.     LINE (x, y)-STEP(765, 40), c~&, B
  129.     LINE (x, y)-STEP(3 * value, 40), c~&, BF
  130.     s$ = label$ + " = " + _TRIM$(STR$(value))
  131.     _PRINTSTRING (x + 384 - 4 * LEN(s$), y + 12), s$
  132.  

Solid:
 
Test Solid max Redand Blue.PNG


50% transparent overlay:
 
Test max Red and Blue at 50% transparent.PNG


Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Color Dialog
« Reply #9 on: June 21, 2019, 03:39:30 pm »
Hi BPlus, do you remember that Alpha changes color depending on the background color? This means that the resulting color will always be of a different appearance but of the same value if you add a different screen clearing color than black to the CLS command on row 57?

This assumes that you apply the obtained value as a color number to different commands. Then there will be color mixing (for alpha < 255) depending on the background. The only way in which background color mixing does not occur is to insert colors into the image directly with the MEM command.

Or set _DONTBLEND.

https://www.qb64.org/wiki/BLEND
https://www.qb64.org/wiki/DONTBLEND
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Color Dialog
« Reply #10 on: June 21, 2019, 03:59:15 pm »
A quick demo to highlight the difference of blended and unblended colors.:

Code: [Select]
SCREEN _NEWIMAGE(640, 480, 32)

CLS , &HFF000000~&
_BLEND
LINE (0, 0)-(640, 480), &H99FFFFFF~&, BF 'faded white background box
PRINT "Black color: "; HEX$(&HFF000000~&)
PRINT "Box color: "; HEX$(&H99FFFFFF~&)
PRINT "Mixed color: "; HEX$(POINT(300, 300))
PRINT "(These are values of blended colors.)"

SLEEP 'Pause for user input


CLS , &HFF000000~&
_DONTBLEND
LINE (0, 0)-(640, 480), &H99FFFFFF~&, BF 'faded white background box
PRINT "Black color: "; HEX$(&HFF000000~&)
PRINT "Box color: "; HEX$(&H99FFFFFF~&)
PRINT "Mixed color: "; HEX$(POINT(300, 300))
PRINT "(These are values of unblended colors.)"

If the color mixer is going to have alpha settings, you'll probably want to run your program in a _DONTBLEND state so that the background doesn't affect the true appearance of the chosen color.  (Or else add a toggle button to swap between Blend and Not Blend, so the user could see how the alpha value would end up actually looking in real conditions with their backgrounds.)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Color Dialog
« Reply #11 on: June 21, 2019, 04:15:53 pm »
Yes. If the user exactly specifies the area where the color will be applied, then the resulting color with the alpha channel application can be shown to the user and set. Without background knowledge, there is no way to determine how the color see, if the alpha channel will be less than 255.