home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 52
/
Amiga_Dream_52.iso
/
RiscOS
/
APP
/
DEVS
/
LIB
/
DOSLIB.ZIP
/
DosLib
/
c
/
ConioDemo
Wrap
Text File
|
1997-03-12
|
4KB
|
186 lines
/*
Name : ConioDemo.c
Purpose : Demonstration program for DOSLib
Author : LogiX
Copyright: ⌐ Topix, 11 March 1997
*/
#include <stdio.h>
#include <stdlib.h>
#include "conio.h"
/******************************************************************************
in: bx, by = box coordinates
w, h = width, height
linestyle = 1 (single) or 2 (double)
bgcolor = background color
borderclr = border color
out: -
desc: draws a box on screen with the given size and attributes
*******************************************************************************/
void draw_box(int bx, int by, int w, int h,
int linestyle, int bgcolor, int borderclr)
{
int y;
char topl, topr, botl, botr, hor, ver;
char *empty;
void *scr;
empty = malloc((w + h + 10) * 4);
if (abs(linestyle == 2))
{
topl = '╔';
topr = '╗';
botl = '╚';
botr = '╝';
ver = '║';
hor = '═';
}
else
{
topl = '┌';
topr = '┐';
botl = '└';
botr = '┘';
ver = '│';
hor = '─';
}
// top
gotoxy(bx, by);
textattr(borderclr);
cprintf("%c", topl);
memset(empty, hor, w + 1);
empty[w + 1] = '\0';
cprintf(empty);
cprintf("%c", topr);
// centre
for (y = by + 1; y < by + h; y++)
{
gotoxy(bx, y);
textattr(borderclr);
cprintf("%c", ver);
textattr(bgcolor);
memset(empty, ' ', w + 1);
empty[w + 1] = '\0';
cprintf(empty);
textattr(borderclr);
cprintf("%c", ver);
}
// bottom
gotoxy(bx, by + h);
textattr(borderclr);
cprintf("%c", botl);
memset(empty, hor, w + 1);
empty[w + 1] = '\0';
cprintf(empty);
cprintf("%c", botr);
if (linestyle > 0)
{
// vertical shadow
gettext(bx + w + 3, by + 1, bx + w + 3, by + h + 1, empty);
for (y = 0; y < h; y++)
empty[y * 2 + 1] = DARKGRAY;
puttext(bx + w + 3, by + 1, bx + w + 3, by + h + 1, empty);
// horizontal shadow
gettext(bx + 1, by + h + 1, bx + w + 4, by + h + 2, empty);
for (y = 0; y < w + 3; y++)
empty[y * 2 + 1] = DARKGRAY;
puttext(bx + 1, by + h + 1, bx + w + 4, by + h + 2, empty);
}
free(empty);
}
/******************************************************************************
in: -
out: EXIT_SUCCESS
desc: demonstrates some of the conio.h functions
*******************************************************************************/
int main(void)
{
int c,
x = 12,
y = 5,
w = 33,
h = 10;
void *screen_mem;
char *colour[] = {"black", "blue", "green", "cyan",
"red", "magenta", "brown", "lightgray",
"darkgray", "lightblue", "lightgreen", "lightcyan",
"lightred", "lightmagenta", "yellow", "white"};
dos_init();
textmode(C80);
clrscr();
printf("All possible colours in a 16 colour mode\n");
printf("Note: in DOS only the first 8 colours can be a background colour");
for (c = 0; c < 16; c++)
{
textattr(c);
gotoxy(1, c + 4);
cprintf("This is colour %d (%s)\n", c, colour[c]);
textattr(WHITE + (c % 8) * 16);
gotoxy(36, c + 4);
cprintf("This is background %d (%s)\n", c, colour[c]);
}
printf("\n\n");
textattr(WHITE);
// read a keycode
printf("Press a key: ");
printf("ASCII code %d\n", getch());
// switch off the cursor
_setcursortype(_NOCURSOR);
// save the screen behind the window
screen_mem = malloc(w * h * 4);
gettext(x, y, x + w, y + h, screen_mem);
// draw the window
draw_box(x, y, w - 3, h - 2, 2, BLUE + BLUE * 16, WHITE + BLUE * 16);
textattr(WHITE + BLUE * 16);
gotoxy(x + 2, y + 2);
cprintf("A simple window with shadow");
gotoxy(x + 2, y + 4);
cprintf("Press any key to continue...");
gotoxy(x + 2, y + 6);
cprintf("and to restore the background");
// wait for a key, restore the background and release the screen memory
getch();
puttext(x, y, x + w, y + h, screen_mem);
free(screen_mem);
textattr(WHITE);
gotoxy(1, 24);
// switch on the cursor
_setcursortype(_NORMALCURSOR);
return EXIT_SUCCESS;
}