Author Topic: Keeping Background Graphics For Text Example  (Read 1074 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Keeping Background Graphics For Text Example
« on: July 03, 2020, 07:28:15 pm »
The neat thing about making a complicating program like Paint Pixels 8, is that I keep learning new stuff. Today I looked through the forum to see if anyone has made transparent backgrounds for text. And you guys have! I had no idea it was possible all this time. There was a post by Pete back in May 2019 (1 month before I started or so) asking about it and you guys put up some examples. Well, I just made my own example. It's the first time I've ever used Windows Fonts for QB64 as well. This will be added to Paint Pixels 8 soon so keep a look out for it. But for now, here is my example for you programmers out there to use and learn by. It is Windows only I believe. It brings up a bunch of different colored circles all over the screen and then it asks for any text and then a size for the font. Then you place it by left clicking anywhere on the screen. And you can keep doing that on the screen for as many of them as you want. To write different text, right click instead. I might add a color picker for Paint Pixels 8 as well. But for now it's only in white because it shows up the best with the black screen and the colors.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2.     c1 = INT(RND * 254) + 1
  3.     c2 = INT(RND * 254) + 1
  4.     c3 = INT(RND * 254) + 1
  5.     sz = (RND * 100) + 10
  6.     x = INT(RND * 800) + 1
  7.     y = INT(RND * 600) + 1
  8.     t = t + 1
  9.     IF t > 1000 THEN GOTO printing:
  10.     CIRCLE (x, y), sz, _RGB32(c1, c2, c3)
  11.  
  12. printing:
  13. IF f& <> 0 THEN f& = _LOADFONT(fontfile$, 18): _FONT f&
  14. copy& = _COPYIMAGE(0)
  15. inputting:
  16. INPUT "Text: ", t$
  17. INPUT "Size (12-72):", sz
  18. IF sz < 12 OR sz > 72 OR sz <> INT(sz) THEN PRINT "Try again.": GOTO inputting:
  19. font$ = "Arial.ttf"
  20. rootpath$ = ENVIRON$("SYSTEMROOT") 'normally "C:\WINDOWS"
  21. fontfile$ = rootpath$ + "\Fonts\" + font$ 'TTF file in Windows
  22. f& = _LOADFONT(fontfile$, sz)
  23. SCREEN copy&
  24. _TITLE "Left click area to place text."
  25.     mouseWheel = 0
  26.         mouseX = _MOUSEX
  27.         mouseY = _MOUSEY
  28.         mouseLeftButton = _MOUSEBUTTON(1)
  29.         mouseRightButton = _MOUSEBUTTON(2)
  30.         mouseMiddleButton = _MOUSEBUTTON(3)
  31.         mouseWheel = mouseWheel + _MOUSEWHEEL
  32.     LOOP
  33.     IF mouseRightButton = -1 THEN GOTO printing:
  34.     IF mouseLeftButton = -1 THEN
  35.         COLOR _RGB32(255, 255, 255)
  36.         _FONT f&
  37.         _PRINTSTRING (mouseX, mouseY), t$
  38.         mouseLeftButton = 0
  39.         _TITLE "Right click to make more text."
  40.     END IF
  41.  

Here is the forum post from May of last year: https://www.qb64.org/forum/index.php?topic=1373.0#top
« Last Edit: July 03, 2020, 07:32:34 pm by SierraKen »