home *** CD-ROM | disk | FTP | other *** search
- Program GetColor; {test program for getattr procedure}
- Uses Crt, Qwik, wndwvars, Wndw, Getvars, Get, Fns;
-
- var
- testchar: char;
- I: byte;
-
-
- procedure getattr(var selattr: byte; display_value: boolean);
- {
- This procedure displays a palette of attributes similar to that used by
- Turbo Pascal's TINST program and allows the user to select one. The
- parameter display_value controls whether or not the decimal value of the
- attribute is displayed at the bottom of the window.
-
- <Ret> selects a foreground and background colour combination (attribute)
- <Esc> aborts leaving the attribute variable passed unchanged
-
- NOTE:
-
- The procedure InitWindow in WNDW40 should be run BEFORE this procedure
- is executed, preferably at the start of the program within which this
- procedure is used.
- }
-
- var row, col: integer;
- strattr: string[3];
- color_window: array[1..864] of byte; {18 * 24 * 2 bytes}
-
-
- procedure display_colors;
- var fg,bg: byte;
- begin
- Qfill(3,4,1,24,7,' '); {clears space for boxtop}
- for fg := 0 to 15 do
- for bg := 0 to 7 do
- Qwrite(succ(fg) + 3, succ(bg * 3) + 3, ord(bg * 16 + fg), ' x ');
- Qfill(20,4,1,24,7,' '); {clears space for box bottom}
- QStoreToMem(3,4,18,24,color_window);
- end;
-
-
- procedure moveto (var r,c: integer);
- var x,y: integer;
- attr,
- attrs,
- attrt,
- attrb: byte; {box attributes, side, top and bottom}
-
- begin
- r := r and $0F; {equivalent to r := r mod 16. See Turbo Tutor manual p316}
- if r = 0 then
- r := 16;
-
- c := c and $07; {equivalent to c := mod 8}
- if c = 0 then
- c := 8;
-
- QStoreToScr(3,4,18,24,color_window); {restore window contents}
-
- x := pred(c * 3) + 3;
- y := r + 3;
- attrs := (pred(c) * 16 + 15);
- attrb := attrs;
- attrt := attrs;
- {
- The top or bottom of the box may stick into space. White on black is 15
- }
- case r of
- 1: attrt := 15;
- 16: attrb := 15;
- end;
-
- Qwrite(pred(y),pred(x),attrt,'┌─┐'); { chr(218) + chr(196) + chr(191) }
- Qwrite(y,pred(x), attrs,'│') ; { chr(179) }
- Qwrite(y,succ(x), attrs,'│') ; { chr(179) }
- Qwrite(succ(y),pred(x),attrb,'└─┘'); { chr(192) + chr(196) + chr(217) };
-
- if display_value then
- begin
- str((pred(col) * 16 + pred(row)),strattr);
- while length(strattr) < 3 do
- strattr := '─' + strattr;
- titlewindow(bottom,right,strattr);
- end;
-
- end; {moveto}
-
-
- begin {get_colors}
- SetWindowModes(ShadowRight);
- MakeWindow(2,3,20,26,32,15,vdoublebrdr,window1);
- titlewindow(top,left,'Attributes');
- ModCursor(CursorOff);
- escaped := false;
- row := 1;
- col := 1;
- display_colors;
-
- repeat
- moveto(row,col);
- command := extendkey;
- action := get_edit(command);
- case action of
- upchar: dec(row);
- downchar: inc(row);
- rightchar: inc(col);
- leftchar: dec(col);
- goto_start: col := 1;
- goto_end: col := 8;
- goto_top: begin
- row := 1;
- col := 1;
- end;
- goto_bottom: begin
- row := 16;
- col := 8;
- end;
- pageup: row := 1;
- pagedown: row := 16;
- escapefrom: escaped := true;
- carriage_return: selattr := pred(col) * 16 + pred(row);
- end;
-
- until (action = carriage_return) or escaped;
-
- ModCursor(CursorOn);
- removewindow;
- end;
-
-
- begin
- initWindow(7,true);
- getattr(I,true);
- textbackground(0); textcolor(7);
- if not escaped then
- write('Attribute selected was ',I)
- else write('No attribute selected');
- end.
-