Author Topic: _printstring question  (Read 4598 times)

0 Members and 1 Guest are viewing this topic.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
_printstring question
« on: October 06, 2020, 08:23:38 am »
I am trying to use printstring to display text on top of a background image.

My question is, "How do I make the background of the text transparent?"

Reason: When I print the text all I get is a string-length 'black box' with the text inside. See attached image.
Logic is the beginning of wisdom.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: _printstring question
« Reply #1 on: October 06, 2020, 08:32:26 am »
hi !

text color let:
COLOR color, 0

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: _printstring question
« Reply #2 on: October 06, 2020, 09:04:00 am »
Brilliant!! Worked like a charm... I have no idea how I could have possibly missed that one.... My apologies for such a thoughtless question. Many thanks. Much appreciated.
Logic is the beginning of wisdom.

FellippeHeitor

  • Guest
Re: _printstring question
« Reply #3 on: October 06, 2020, 09:45:34 am »
You can also:
Code: QB64: [Select]

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: _printstring question
« Reply #4 on: October 06, 2020, 01:37:12 pm »
hi !

text color let:
COLOR color, 0

@MasterGy COLOR color, 0

Is that in v1.4? I have 1.3, and that gives the expected, "Name already in use.." IDE error. I don't print text over background images, but I may want to in the future.

I can do transparencies with the Windows API, but I can also hit myself in the head with a hammer. It saves the wife the bother.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: _printstring question
« Reply #5 on: October 06, 2020, 06:01:40 pm »
Fillippe,

_PRINTMODE also worked like a charm. Wow. Two methods to do the same thing... Cool

As I tested printmode it reminded me of another question... (No. Do tell, you say... lol)

Obviously QB64 creates a view-able 'window' when it executes... but is there a method to place that window central to the monitor... Each time I run QB64 I have to 'drag' the window to the centre. (I know... It's SUCH an effort... lol)

J

ps: Before I forget... Thanks for your advice...
« Last Edit: October 06, 2020, 06:03:12 pm by johnno56 »
Logic is the beginning of wisdom.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: _printstring question
« Reply #6 on: October 06, 2020, 06:10:01 pm »
Fillippe,

_PRINTMODE also worked like a charm. Wow. Two methods to do the same thing... Cool

As I tested printmode it reminded me of another question... (No. Do tell, you say... lol)

Obviously QB64 creates a view-able 'window' when it executes... but is there a method to place that window central to the monitor... Each time I run QB64 I have to 'drag' the window to the centre. (I know... It's SUCH an effort... lol)

J

ps: Before I forget... Thanks for your advice...


SCREEN _NEWIMAGE(640,480,32)
_DELAY 0.2
_SCREENMOVE _MIDDLE
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: _printstring question
« Reply #7 on: October 06, 2020, 06:45:55 pm »
Thanks Steve.

Why the "_delay"? (The command. Not the speed at which you responded. lol)
Just curious...

J
Logic is the beginning of wisdom.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: _printstring question
« Reply #8 on: October 06, 2020, 07:11:19 pm »
Thanks Steve.

Why the "_delay"? (The command. Not the speed at which you responded. lol)
Just curious...

J

To prevent any race conditions from glitching up the command when you first start up a QB64 SCREEN.  Take a moment to think of how QB64 starts...

*ALL* QB64 programs start in a default SCREEN 0 window. 
Windows requires a few cycles to register that default SCREEN 0 window handle, and then give it to us so we can use it.
_SCREENMOVE works off that handle...

But what if we call _SCREENMOVE before we get that handle?  (Spoiler: NOTHING happens.  We try to move a null-handle window, so do nothing at all...)

Now, add in a screen change with:  SCREEN. _NEWIMAGE(640, 480, 32)
Once again, windows will update handles and such, and send us back that information.

But what if you call _SCREENMOVE before the new handle comes back?  (Spoiler: You move that original SCREEN 0 window, miliseconds before it closes forever.)

To prevent these issues, it’s a good idea to implement a slight _DELAY after swapping SCREEN modes, and before moving that screen.

Once the screen is initialized, you can move it all you want, with no problems or worries, but if you’re going to use a SCREEN change, with _SCREENMOVE after, *always* add a miniscule delay to allow windows time to make and register your handles and such, before using them.


https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: _printstring question
« Reply #9 on: October 06, 2020, 07:13:51 pm »
Some commands are a bit tie sensitive. If you don't put in a delay, the command may be missed. This is most notable when doing AI calls in Windows.  In keyboard INKEY$ programs, _delay of .04 makes it possible to hold a key down, and not get jumpy results, like when using an arrow key to enlarge or decrease a screen, text window, etc.

Now since MasterGY has not returned, @johnno56, is COLOR color, 0 something new to v1.4? I don't know of a keyword used in an argument in QB.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: _printstring question
« Reply #10 on: October 06, 2020, 07:18:23 pm »
Now since MasterGY has not returned, @johnno56, is COLOR color, 0 something new to v1.4? I don't know of a keyword used in an argument in QB.

Pete

I’m fairly certain he’s not talking about using color as a variable, or constant.  It’s just in his example as a placeholder to illustrate usage.

COLOR WhateverForegroundValueYouWant, 0

The ,0 sets a 0 red, 0 green, 0 blue, 0 alpha transparent colored background.

Easier usage is just:

COLOR , 0
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: _printstring question
« Reply #11 on: October 06, 2020, 07:37:03 pm »
That makes more sense. I was hoping the team wasn't breaking from convention. COLOR , 0. I've never tried it, but I'll keep it in mind. It looks to be something I might want to use sometime. THANKS!

Pete

On the first day, God created SCREEN 0. On the weekend, he created all the others. Why? So when he created man, a couple of days later, man would appreciate SCREEN 0 even more!
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: _printstring question
« Reply #12 on: October 06, 2020, 07:54:51 pm »
Thanks guys for the explanation. Much appreciated.

J
Logic is the beginning of wisdom.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: _printstring question
« Reply #13 on: October 07, 2020, 12:03:01 am »
Sorry, I'm writing now. I don't know the deeper reason for COLOR, 0, but I've been using this since dos qb4.5 if I don't want to remove the background below the text.

It is well described here:
https://www.qb64.org/wiki/COLOR