Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrows and highlighting

Status
Not open for further replies.

gwar2k1

Programmer
Apr 17, 2003
387
0
0
GB
Hey, just a few questions about arrow keys and doing the menu thing where it "highlights" a selection...

To use the arrow keys which are extended ASCII, I use this function:

FUNCTION keyread:integer;

VAR
value:integer;

BEGIN
value := ord(upcase(readkey));
IF value = 0 THEN
value := ord(readkey) + 300;
keyread := value;
END;

This works, however, I have to press the key twice before I get a result. I cant think of why it does this nor can I work out how to get rid of it =(
Do you guys use any other function to retrieve extended ASCII that works when you press the key once? lol

OK, so with that - and I guess every othe function with the same purpose - the arrow keys are 372: Up and 380: Down.
In a CASE keyread OF <value> I have an IF.

IF y > (highest menu positon) THEN
BEGIN
y = y + 1
item = item - 1
bgcolor : white
text : black
gotoxy(x{set},y)
writeln(array[item])
...

That displays the highlighted item from the array &quot;on top&quot; of the one that wasnt highlighted.

...
bgcolor(black)
text(white)
gotoxy(x,y-1)
writeln(array[item-1])
END

So that *should* write the previous selection in the &quot;normal&quot; colors, though it doesnt work 100% I really dont know why, If it can work once it can work twice right? lol wrong! =S
Of course, the down IF has y - 1 and item + 1 etc.

Besides it not working all the time, there is no way with that method to highlight the 1st item then clear it. Same with the last item. Again, I dont understand why. In theory that should work.

It could just be my tempramental Turbo Pascal (7.1) but Im not sure.

So there's the second plea: Highlighting techniques.

Sorry to be greedy just I dip in to this area of design occasionally and over a period of two years Ive still yet to come up with a solution that works! Yes, I am slow =P

Thanks for your time

~*Gwar3k1*~
&quot;To the pressure, everything's just like: an illusion. I'll be losing you before long...&quot;
 
OK, ive been testing and i can now get it to highlight in the correct place when the menu is placed any where on screen BUT now for some unknown reason the keys arent working =(

PROGRAM test;

PROCEDURE writeln(x,y:byte; s:string);
{display procedure. allows frames to be placed full screen and removes the need for gotoxy}

VAR
i,j : word;
color : word;
sreenwidth : integer;
screenheight : integer;

BEGIN
IF (x = 0) OR (y = 0) THEN
exit;
x := x + lo(Windmin)-1;
y := y + hi(Windmin)-1;
IF (x > lo(windmax)) OR (y > hi(windmax)) THEN
exit;
IF x+length(s)-1 > lo(windmax) THEN
s := copy(s, 1, lo(windmax)-x+1);
sreenwidth := memw[Seg0040:$4a];
i := ( y * SreenWidth + x ) * sizeof(word);
color := textattr;
color := color shl 8;
FOR j := 1 TO length(s) DO
BEGIN
memw[segB800:i] := color OR ord(s[j]);
inc(i,2);
END;
END;

PROCEDURE clrscr(x1,y1,x2,y2:byte);

VAR
i,y : integer;

BEGIN
y := y1 - 1;
REPEAT
y := y + 1;
FOR i := x1 TO x2 DO
writeln(i,y,' ');
UNTIL y = y2;
END;

PROCEDURE menu(s:ARRAY OF string; x,y,h,m:integer);
{(s)tring, (h)ighlighted // y axis, (m)enu_size}

VAR
b,c : integer; {(b)lank_space, (c)urrent, (l)ength}

BEGIN
m := m - 1;
FOR c := 0 TO m DO
BEGIN
IF c = h - 1 THEN
BEGIN
textcolor(black);
textbackground(lightgray);
END
ELSE
BEGIN
textcolor(lightgray);
textbackground(black);
END;
FOR b := 1 TO 10 DO
writeln(x+b,y,#32);
writeln(x,y+c,s[c]);
END;
END;

PROCEDURE menu2(VAR key:char; VAR y,m,z:integer);

BEGIN
REPEAT
key := readkey;
UNTIL key IN [#13,#72,#80];
CASE key OF
#72 : y := y - 1;
#80 : y := y + 1;
END;
IF y < z THEN
y := m;
IF y > (z + m) THEN
y := z;
END;

CONST
s : ARRAY [0..8] OF string = ('A','B','C','D','E','F','G','H','I');

VAR
y,m,z : integer;
key : char;

BEGIN
y := 1;
m := 8;
z := y;
clrscr(1,1,80,50);
menu(s,1,y,1,m);
REPEAT
menu2(key,y,m,z);
UNTIL key = #13;
END.

Thats the program im using to test it and in theory it should work. =@( Can any one help me please?


~*Gwar3k1*~
&quot;To the pressure, everything's just like: an illusion. I'll be losing you before long...&quot;
 
You replace the writeln procedure with your own version, you shouldn't do that! Besides, your version is rather complicated; a procedure writexy containing gotoxy and write should do the job perfectly.

You replace the clrscr procedure with your own version, again: you shouldn't do that! Clrscr clears the active screen window, if you want to wipe a rectangular part of the screen, you can use the window procedure to define a new window, perform a clrscr and reset the window to the full screen size.

The reason why your keys don't seem to work is that you don't react on a keypress; you adjust the y value in menu2, you stay in the main repeat-until loop and you call menu2 again. No displaying in between?!

One other remark: pressing 'P' will have the same result as pressing ArrDn and pressing 'H' will have the same effect as pressing ArrUp. Use the following:
Code:
repeat
  ch:=readkey;
  if ch=#0 then ch2:=readkey;
until (ch in [#13]) or ((ch=#0) and (ch2 in [#72,#80]));

Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
Don't worry what people think about you. They're too busy wondering what you think about them.
 
lmao i cant believe i just did that! ive been a lil distracted to day so um sorry for wasting your time but thanks for the readkey stuff, I was pondering woulding H and P have the same effect.
Ive used window thrice before. ... yeah I get confused with it, it was never something i particularly needed. Any who, back to the code I go =D

Thanks again

~*Gwar3k1*~
&quot;To the pressure, everything's just like: an illusion. I'll be losing you before long...&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top