Page 1 of 1 1
Topic Options
#80983 - 2002-06-20 08:41 PM @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
It would be nice to have macros that:

1. Returned the cursor position:
$x = @CursorX
$y = @CursorY

2. Returned the maximum cursor positions (screen dimensions)
$x = @ModeX
$y = @ModeY

It would be nice to have a function that:

3. reads the screen and put the info into a string.

$string = GetScr($x,$y,$numchars)

Brian

[ 20 June 2002, 20:43: Message edited by: BrianTX ]

Top
#80984 - 2002-06-20 08:44 PM Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
and could simulate a click at the specified coordinates....
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#80985 - 2002-06-21 05:23 PM Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
Actually, Radimus... I wasn't talking about the cursor as in terms of mouse cursor position, although that might be another good idea. I was referring to the command-mode environment.

Brian

Top
#80986 - 2002-06-21 05:32 PM Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I would really like to see this function:

$string = GetScr($x,$y,$numchars)

But, one of the problems is that along with the character, one would want the COLOR information as well ... that might be trickier to do ? But if GetScr return an array of longs, and say the lower word/byte was the char, and the upper word/byte was the color - that would be sweet. One could save and restore the screen and bui;ld some really slick windows libraries.

-Shawn

Top
#80987 - 2002-06-21 05:54 PM Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
Hmm. that makes sense, Shawn. I'm not sure that adding the color doesn't dilute the function. I suppose it could return an array in the form:

$ok = GetScr(0,0,10)

$string = $ok[0]
$stringforeground = $ok[1]
$stringbackground = $ok[2]

; LEN($ok[0])=LEN($ok[1])=LEN($ok[2])

For $N = 1 to LEN($ok[0])
$character = SUBSTR($ok[0],$N,1)
$foreground = SUBSTR($ok[1],$N,1)
$foreground = VAL("&$foreground")
$background = SUBSTR($ok[2],$N,1)
$foreground = VAL("&$foreground")
Next

Something like this... using HEX to identify the color... although I'm not sure... it might be nice to specify in the function that you actually want the color attributes:

$ok = GetScr($x,$y,$numchars,Optional $color)

$color would be set to 1 if you want to return the background and 2 if you want to return the foreground color.... just a thought.

Brian

Top
#80988 - 2002-06-21 06:01 PM Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Was just doing some research into the Windows Console API's. The way it's done there is that there are two functions, one to read the chars, and one the read the colors, for example:

$chars = GetScreenChars(...)

$attribs = GetScreenAttribs(...)

then, one could put them back out, in two passes, using the PutScreenXXX functions ...

Top
#80989 - 2002-06-21 06:05 PM Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Howard,

Do any of these function returning alternatives harp back to a previoius discussion we had about this, just today via email ?

Top
#80990 - 2002-06-24 10:00 AM Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Add the facility to size the console and you've got the potential for a great library.

"Curses for KiXtart" anyone?

Returning the attributes as a seperate value would probably easier, as that would avoid AND/ORing and bitwise shifting and not everyone who does KiXtart scripting is comfortable with bitwise manipulations.

Is a blank area of the screen occupied by a space character, or a Chr(0)? If the former you would get away with strings, if the latter it would need to be an array of ints/doubles.

Top
#80991 - 2002-06-25 05:46 AM Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
Hmmm. Lots of good thoughts on this. After lots of thinking, I'm still not sure whether I'd prefer an array returned for the color attributes or not.

GetScr($x,$y,$numchars) would be okay as is.

I suppose there are things to be said against the color mask being returned in HEX, but I actually would prefer it that way.

GetScrAttr($x,$y,$numchars)

Could return a string in HEX where every two hex numbers would represent foreground and background like:

White on black text -
GetScrAttr(1,1,5)
would return a string "0F0F0F0F0F" or something similar to that. Alternately it could return:

0,15,0,15,0,15,0,15,0,15

(this could be reversed if you assume the foreground comes first)

How do other programming languages do this?

Brian

{p.s. some programming would be simplified if the first character in a SUBSTR was numbered 0 instead of 1... although some other programming would be more difficult.. lol)

Top
#80992 - 2002-06-25 10:05 AM Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Normally attributes are collected together in a single integer, or large integer, and you use binary math to evaluate /set them.

Some definitions:
code:
$BLACK=0
$BLUE=1
$GREEN=2
$CYAN=3
$RED=4
$MAGENTA=5
$YELLOW=6
$WHITE=7
$BLINK=8
$BITMASK=&0F

Now these colours can be stored in just four bits(1,2,4,8, or &0F), which means that the foreground and background colours can both be stored in 8 bits, or a byte (short integer).

To get the colour of the foreground assuming $iAttribute is the attribute value of the screen location:
code:
$iForeColour=($iAttribute & $WHITE)
If $iForeColour=$RED
"Foreground is red"
EndIf

To see if the foreground blink/highlight sttribute is set:
code:
If $iAttribute & $BLINK
"Foreground blink is set" ?
EndIf

The background attributes work exactly the same way, except you need to shift the bits before you can compare them. This is simply done by dividing the value by 16.
code:
$iForeColour=($iAttribute / 16) & $WHITE

To set the bits you just work in reverse. To set yellow flashing text on a blue background:
code:
$iAttribute=( $YELLOW |$BLINK ) | ( 16 * ( $BLUE | $BLINK ) )

This is a fast efficient way of storing attribute information, and is how you would do it in 'C'.
It allows you to use a host of programming tricks to simplify and speed up programs. Early games used to use attributes for collision detection, and making all the things that can blow you up high intensity simplifies the code a lot [Smile]

The problem is that bitwise math is not everyone's cup of tea.

Top
#80993 - 2002-06-25 06:46 PM Re: @CursorX, @CursorY, @ModeX, @ModeY, GetScr()
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
Yep.. that looks good, Richard. I would guess that if you've gotten far enough to even be using screen attributes, you should be able to figure out bitwise math, too! [Smile]

Brian

Top
Page 1 of 1 1


Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 764 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.062 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org