DrawText() -- black font?

Just starting out? Need help? Post your questions and find answers here.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

DrawText() -- black font?

Post by jassing »

I have this code:

Code: Select all

nWidth=16:nHeight=16:nTemp.f=99.9

  hImage = CreateImage(#PB_Any, nWidth + 4, nHeight, 32, RGB(212,208,200))
  If StartDrawing(ImageOutput(hImage))
  	DrawText(1,1,StrF(nTemp,0));,RGB(0,0,0),RGB(254,254,254))
  	;Debug DrawText(1,1,StrF(nTemp,0),RGB(254,254,254),RGB(0,0,0))
  	
  	StopDrawing()
  endif 
My problem is, no matter what I do, I end up with a black box -- if I comment out the drawtext, an image with light gray is created. But I want to draw a black text on that image -- but I keep getting a black box appearing... I know this must be something stupid I'm missing (it's late here,3am, so sleep may help)
flood
User
User
Posts: 32
Joined: Sun Aug 14, 2011 10:32 pm

Re: DrawText() -- black font?

Post by flood »

The default font size is too big for the 20x16 image. So load a a smaller font, ie:

Code: Select all

nWidth=16:nHeight=16:nTemp.f=99.9
  LoadFont(0,"Arial",8)
  hImage = CreateImage(#PB_Any, nWidth + 4, nHeight, 32, RGB(212,208,200))
  If StartDrawing(ImageOutput(hImage))
     DrawingFont(FontID(0))
     ;DrawingMode(#PB_2DDrawing_Transparent) ; Uncomment for transparent BG
     DrawText(1,1,StrF(nTemp,0));,RGB(0,0,0),RGB(254,254,254))
     DrawText(1,1,StrF(nTemp,0),RGB(254,254,254),RGB(0,0,0))
     StopDrawing()
  EndIf 
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: DrawText() -- black font?

Post by TI-994A »

jassing wrote:...I want to draw a black text on that image...
Hello jassing. Like flood said, just set the drawing mode to transparent, and use a slightly smaller font, and you'll get your black text on the grey box: :wink:

Code: Select all

nWidth=16: nHeight=16: nTemp.f=99.9
LoadFont(0, "Arial", 8)
hImage = CreateImage(#PB_Any, nWidth + 4, nHeight, 32, RGB(212,208,200))
If StartDrawing(ImageOutput(hImage))
  DrawingFont(FontID(0))
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawText(1, 1, StrF(nTemp,0), RGB(0,0,0))
  StopDrawing()
EndIf

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(1, #PB_Any, #PB_Any, 100, 100, "Test", wFlags)
SetWindowColor(1, RGB(100, 100, 200))
ImageGadget(2, 20, 20, 0, 0, ImageID(hImage))

While WaitWindowEvent() ! #PB_Event_CloseWindow : CloseWindow : Wend 
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: DrawText() -- black font?

Post by jassing »

Thanks! I'll give that a try.... was frustrated last night...
I knew it was something simple; but i don't think I'd have gotten that on my own.
Cheers!
Post Reply