Recent

Author Topic: Video unit and writeln color?  (Read 5549 times)

Dobesov

  • New member
  • *
  • Posts: 7
Video unit and writeln color?
« on: April 08, 2014, 09:18:44 pm »
we are not supposed to use video and CRT together, however, writeln is not part of the CRT unit. Video has no way to change the text draw color, so how do you alter the write/writeln color attribute when using the video unit? Or are we not supposed to use write/writeln when using video?

-Thanks

Leledumbo

  • Hero Member
  • *****
  • Posts: 8325
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Video unit and writeln color?
« Reply #1 on: April 09, 2014, 05:51:43 am »
The overview page of video unit clearly explains how to change text color and background.

Dobesov

  • New member
  • *
  • Posts: 7
Re: Video unit and writeln color?
« Reply #2 on: April 09, 2014, 04:03:26 pm »
I can tell you my system stats and version but its not pertinent to my question. I have looked over the documentation googled for answers. This is not a Bug or platform issue. Its a general programming question based on the unit documentation.

I suppose the answer may be write your own new writeln function... but I figured I would ask before having to re-create parts of the CRT unit with the video Unit.

I'm running Free Pascal 2.6.2 64bit on Windows 7 sp1, 8.1 and ubuntu 14.04.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8325
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Video unit and writeln color?
« Reply #3 on: April 09, 2014, 05:34:42 pm »
Quote
I have looked over the documentation googled for answers. This is not a Bug or platform issue. Its a general programming question based on the unit documentation.
Did you even read the link I give above?
Quote
I suppose the answer may be write your own new writeln function...
You can't, writeln is NOT a regular function/procedure. It's a compilerproc, meaning it's like a command for the compiler and the compiler will replace it with correct function call based on the given arguments.

Dobesov

  • New member
  • *
  • Posts: 7
Re: Video unit and writeln color?
« Reply #4 on: April 09, 2014, 07:14:40 pm »
Sorry... I actually missed your link... the signature was so long I just caught the how to write a post, lol. I have readd the video unit documentation....

I know how to write a colored character to a video cell, but that doesn't effect the write/writeln color. there must be a variable somewhere that contains the active write color... unless I am totally missing something. The doc uses "Attr" as an example variable, but there is nothing that I see in the video unit variables as the active text color that would effect the default write...

Maybe I am just crazy here.

engkin

  • Hero Member
  • *****
  • Posts: 2692
Re: Video unit and writeln color?
« Reply #5 on: April 09, 2014, 07:48:43 pm »
How about using SetConsoleTextAttribute:
Code: [Select]
uses
 ..., Windows;
...
  WriteLn('Before using SetConsoleTextAttribute');
  WriteLn('');

  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN or FOREGROUND_INTENSITY);

  WriteLn('After using SetConsoleTextAttribute');
  ReadLn;

taazz

  • Hero Member
  • *****
  • Posts: 5365
Re: Video unit and writeln color?
« Reply #6 on: April 09, 2014, 08:41:54 pm »
Quote
After calling InitVideo, the array VideoBuf contains a representation of the video screen of size ScreenWidth*ScreenHeight, going from left to right and top to bottom when walking the array elements: VideoBuf[0] contains the character and color code of the top-left character on the screen. VideoBuf[ScreenWidth] contains the data for the character in the first column of the second row on the screen, and so on.

To write to the 'screen', the text to be written should be written to the VideoBuf array. Calling UpdateScreen will then cp the text to the screen in the most optimal way. (an example can be found further on).

So no writeln is not to be used with video unit, you can use writestr to format your string as needed add the colors and then move it to the buffer.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9265
  • FPC developer.
Re: Video unit and writeln color?
« Reply #7 on: April 09, 2014, 08:45:11 pm »
Video current doesn't trap write/writeln.  It can probably be added using the same way that unit Crt does, but that requires maintaining more state in unit video.

This gets more complicated as you add more features. Unicode support (length(string) is no longer the number of glyphs), Windows() support etc.

None of which are truly surmountable, sb just has to do it, port it to the various targets and, most importantly, follow up for a while.

Unfortunately, textmode I/O is not really hot with volunteers atm.


Dobesov

  • New member
  • *
  • Posts: 7
Re: Video unit and writeln color?
« Reply #8 on: April 09, 2014, 08:50:13 pm »
Cool, thanks guys! I'll just implement a quick and dirty string buffer for output to the video memory! Its more than I wanted to have to do, but it will give me the opportunity to make some extra wizbang effects...

Yeah, it was just a little confusing since write and writeln are not part of CRT and that's what it expressly said in the docs.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9265
  • FPC developer.
Re: Video unit and writeln color?
« Reply #9 on: April 09, 2014, 09:05:56 pm »
Yeah, it was just a little confusing since write and writeln are not part of CRT and that's what it expressly said in the docs.

write/writeln are system functions. They call internal functions that are redirectable though. An example outside the various *crt units is streamio.

 

TinyPortal © 2005-2018