QB64 Phoenix Edition
Using color in Draw string - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: Using color in Draw string (/showthread.php?tid=2573)

Pages: 1 2 3 4


Using color in Draw string - PhilOfPerth - 04-04-2024

How do I (or can I) nominate a colour for the string in this code?

Code: (Select All)
WWidth = 1120: WHeight = 820: Mode = 32: Size = 24
Screen _NewImage(WWidth, WHeight, Mode)
SetFont: f& = _LoadFont("C:\WINDOWS\fonts\courbd.ttf", Size, "monospace"): _Font f&
lhs = (_DesktopWidth - WWidth) / 2
_ScreenMove lhs, 86 ' centre display on screen
CPL = WWidth / _PrintWidth("X")

PSet (500, 200): Draw "r100d100l100u100"
Sleep


 I've tried adding C3 etc to the front, which is accepted but ignored, and C_rgb(...) which errors out.


RE: Using color in Draw string - SMcNeill - 04-04-2024

You're in 32-bit screen mode; you have to use 32-bit color values as below:

Code: (Select All)
WWidth = 1120: WHeight = 820: Mode = 32: Size = 24
Screen _NewImage(WWidth, WHeight, Mode)
SetFont: f& = _LoadFont("C:\WINDOWS\fonts\courbd.ttf", Size, "monospace"): _Font f&
lhs = (_DesktopWidth - WWidth) / 2
_ScreenMove lhs, 86 ' centre display on screen
CPL = WWidth / _PrintWidth("X")

Print &HFFFF0000& 'Red
Print &HFF00FF00& 'Green
Print &HFF0000FF& 'blue

PSet (500, 200): Draw "r100 c-65536 d100 c-16711936 l100 c-16776961 u100"
Sleep



RE: Using color in Draw string - PhilOfPerth - 04-04-2024

Ah, got it!
You nailed it again. Thanks Steve!


RE: Using color in Draw string - PhilOfPerth - 04-04-2024

I get how to place the colours in the string, but what I don't get is how the hex codes are interpreted. Which "digits" set which colour?

&HFFFF0000& 'Red
Seemed pretty obvious at first- full slab  of red, and nothing else (but where are the third group of colour digits?)
 
&HFF00FF00& 'Green
Here I get even more confused: 255 portions of red, and ... ???

 &HFF000000& 'blue   Huh


RE: Using color in Draw string - SMcNeill - 04-04-2024

AARRGGBB, in hex.

Alpha Red Green Blue.

2 hex values represented for 0 to 255 in each.


RE: Using color in Draw string - PhilOfPerth - 04-04-2024

Completely forgot about Alpha!
And I messed up your codes, sorry
Ok, try again!


RE: Using color in Draw string - Pete - 04-04-2024

Did someone say DRAW, varmints!

Code: (Select All)
WWidth = 1120: WHeight = 820: Mode = 32: Size = 24
Screen _NewImage(WWidth, WHeight, Mode)
SetFont: f& = _LoadFont("C:\WINDOWS\fonts\courbd.ttf", Size, "monospace"): _Font f&
lhs = (_DesktopWidth - WWidth) / 2
_ScreenMove lhs, 86 ' centre display on screen
CPL = WWidth / _PrintWidth("X")
Dim As _Unsigned Long red, green, blue
red = _RGB(102, 0, 0, 255)
green = _RGB(0, 102, 0, 255)
blue = _RGB(0, 0, 102, 255)
Print "r100 c" + Str$(red) + " d100 c" + Str$(green) + " l100 c" + Str$(blue) + " u100"
PSet (500, 200): Draw "r100 c" + Str$(red) + " d100 c" + Str$(green) + " l100 c" + Str$(blue) + " u100"
Sleep


Errr better still...

Code: (Select All)
$Color:32
WWidth = 1120: WHeight = 820: Mode = 32: Size = 24
Screen _NewImage(WWidth, WHeight, Mode)
SetFont: f& = _LoadFont("C:\WINDOWS\fonts\courbd.ttf", Size, "monospace"): _Font f&
lhs = (_DesktopWidth - WWidth) / 2
_ScreenMove lhs, 86 ' centre display on screen
CPL = WWidth / _PrintWidth("X")
Print "r100 c" + Str$(Red) + " d100 c" + Str$(Green) + " l100 c" + Str$(Blue) + " u100"
PSet (500, 200): Draw "r100 c" + Str$(Red) + " d100 c" + Str$(Green) + " l100 c" + Str$(Blue) + " u100"
Sleep

Pete


RE: Using color in Draw string - TerryRitchie - 04-04-2024

(04-04-2024, 09:19 AM)PhilOfPerth Wrote: Completely forgot about Alpha!
And I messed up your codes, sorry
Ok, try again!

The first sections in lesson 14 of the tutorial explains how the color codes work if you would like a refresher.

https://www.qb64tutorial.com/lesson14


RE: Using color in Draw string - Dimster - 04-04-2024

Terry - I do find your tutorials very very helpful and your suggestion here to Phil sure does help me understand better exactly what the problem is that Phil is running into and the potential solution. The little annoying thing that I'm running into however is leaving my coding and accessing the digital version of reference material,(in which I place your tutorial) or doing a search on this forum for more insight. I'd much prefer (likely I'd be in the minority here) to have a hard copy manual/binder of reference material beside me to lookup stuff while I'm starring at my code. 

Wouldn't it be nice if you and Steve could get together a produce a hard copy of your tutorial and Steve's (almost completed) bible. Place that as one of the items we can buy on this forum site along with the coffee mugs. Just saying.


RE: Using color in Draw string - Pete - 04-04-2024

Hell, you could place everything Steve knows about QB64 on the COFFEE MUG and still have room for a full size image of Yosemite Sam on the back! (He's really that short!) J/K

Steve's response: Pete is absolutely right, you'd just have to print it in a .0001 pixel font.

Pete Big Grin