📄 examp001.c
字号:
*/
char *color_translate(int color)
{
switch(color) {
case BLACK : return("BLACK");
case BLUE : return("BLUE");
case GREEN : return("GREEN");
case CYAN : return("CYAN");
case RED : return("RED");
case MAGENTA : return("MAGENTA");
case BROWN : return("BROWN");
case LIGHTGRAY : return("LIGHTGRAY");
case DARKGRAY : return("DARKGRAY");
case LIGHTBLUE : return("LIGHTBLUE");
case LIGHTGREEN : return("LIGHTGREEN");
case LIGHTCYAN : return("LIGHTCYAN");
case LIGHTRED : return("LIGHTRED");
case LIGHTMAGENTA: return("LIGHTMAGENTA");
case YELLOW : return("YELLOW");
case WHITE : return("WHITE");
}
return(NULL);
}
/*----------------------------------------------------------------------------
* Restore the background under the text pointed to by "locations".
*/
void erase_text(int locations[][3], int number)
{
register int i;
for (i = 0; i < number; i++)
_16_restore_bg(locations[i][0], locations[i][1]+2, locations[i][2],
TEXTHEIGHT-2, bgscrn);
}
/*----------------------------------------------------------------------------
* Exiting sequence.
*/
void exit_sequence(void)
{
closegraph(); /* shut down graphics system */
kbd_status_load();
ms_hide(); /* hide mouse cursor */
video_restore(oldmode); /* restore original video status */
exit(0); /* exit to DOS with ERRORLEVEL 0 */
}
/*----------------------------------------------------------------------------
* Restore the background.
*/
void restore_background(void)
{
/* overwrite the remaining images on the screen to restore the background */
_16_restore_bg(image_c[0]->x, image_c[0]->y,
image_c[0]->length, image_c[0]->height, bgscrn);
_16_restore_bg(image_p[0]->x, image_p[0]->y,
image_p[0]->length, image_p[0]->height, bgscrn);
_16_restore_bg(image_i[0]->x, image_i[0]->y,
image_i[0]->length, image_i[0]->height, bgscrn);
}
/*----------------------------------------------------------------------------
* Print the image properties onscreen.
*
* "x","y" - coordinates of the first line of properties
* "image" -
* "image_name" - string name of the image
* "image_cmnd" -
*/
void print_image_properties(int x, int y, imagedata *image, char *image_name,
char *image_cmnd, int locations[][3])
{
str_copy(&message[0], image_name); /* copy "image_name" */
str_copy(&message[10], "->size = %d"); /* copy "image->size" */
sprintf(buffer, message, image->size); /* define "buffer" */
PRINT(x, y, buffer); /* print "buffer" */
locations[0][0] = x, locations[0][1] = y,
locations[0][2] = textwidth(buffer); /* save text data */
str_copy(&message[10], "->tclr = %s");
sprintf(buffer, message, color_translate(image->tclr));
y += TEXTHEIGHT-1; /* adjust y-coordinate */
PRINT(x, y, buffer); /* print "buffer" */
locations[1][0] = x, locations[1][1] = y,
locations[1][2] = textwidth(buffer); /* save text data */
str_copy(&message[10], "->x = %d");
sprintf(buffer, message, image->x);
y += TEXTHEIGHT-1; /* adjust y-coordinate */
PRINT(x, y, buffer); /* print "buffer" */
locations[2][0] = x, locations[2][1] = y,
locations[2][2] = textwidth(buffer); /* save text data */
str_copy(&message[10], "->y = %d"); /* copy "image->y" */
sprintf(buffer, message, image->y);
y += TEXTHEIGHT-1; /* adjust y-coordinate */
PRINT(x, y, buffer); /* print "buffer" */
locations[3][0] = x, locations[3][1] = y,
locations[3][2] = textwidth(buffer); /* save text data */
str_copy(&message[10], "->length = %d"); /* copy "image->length" */
sprintf(buffer, message, image->length); /* define "buffer" */
y += TEXTHEIGHT-1; /* adjust y-coordinate */
PRINT(x, y, buffer); /* print "buffer" */
locations[4][0] = x, locations[4][1] = y,
locations[4][2] = textwidth(buffer); /* save text data */
str_copy(&message[10], "->height = %d"); /* copy "image->height" */
sprintf(buffer, message, image->height); /* define "buffer" */
y += TEXTHEIGHT-1; /* adjust y-coordinate */
PRINT(x, y, buffer); /* print "buffer" */
locations[5][0] = x, locations[5][1] = y,
locations[5][2] = textwidth(buffer); /* save text data */
str_copy(&message[10], "->how = %s"); /* copy "image->how" */
sprintf(buffer, message, t_or_f(image->how)); /* define "buffer" */
y += TEXTHEIGHT-1; /* adjust y-coordinate */
PRINT(x, y, buffer); /* print "buffer" */
locations[6][0] = x, locations[6][1] = y,
locations[6][2] = textwidth(buffer); /* save text data */
str_copy(&message[0], image_cmnd); /* copy "image_cmnd" */
y += (TEXTHEIGHT-1)*2; /* adjust y-coordinate */
PRINT(x, y, message); /* print "message" */
locations[7][0] = x, locations[7][1] = y,
locations[7][2] = textwidth(message); /* save text data */
}
/*----------------------------------------------------------------------------
* Draw and save the background image.
*/
void save_background(void)
{
register int i, ii;
/* first, draw the border */
for (i = 0; i < 5; i++)
_16_boxoutline(i, i, MAXX - i*2, MAXY - i*2, YELLOW, COPY_IMAGE);
/* next, draw the background */
for (i = BLACK, ii = 5; i <= WHITE; i++, ii += 21)
_16_boxfill(ii, 5, 21, MAXY - 10, i, COPY_IMAGE);
for (i = YELLOW; i > BLACK; i--, ii += 21)
_16_boxfill(ii, 5, 21, MAXY - 10, i, COPY_IMAGE);
/* and finally, save the background into memory */
_16_i_save(0, 0, MAXX, 204, bgscrn[0], FALSE, TRUE);
_16_i_save(0, 204, MAXX, 204, bgscrn[1], FALSE, TRUE);
_16_i_save(0, 408, MAXX, 204, bgscrn[2], FALSE, TRUE);
_16_i_save(0, 612, MAXX, 204, bgscrn[3], FALSE, TRUE);
}
/*----------------------------------------------------------------------------
* Draw and save the images.
*/
void save_images(void)
{
/* draw a simple image offscreen (so as not to disturb the background) */
_16_boxfill(10, MAXY+10, 50, 50, LIGHTRED, COPY_IMAGE); /* 50 by 50 box */
_16_boxfill(20, MAXY+20, 30, 30, LIGHTGREEN, COPY_IMAGE);/* 30 by 30 box */
_16_boxfill(20, MAXY+30, 30, 10, BLACK, COPY_IMAGE); /* 30 by 10 box */
_16_boxfill(30, MAXY+20, 10, 30, BLACK, COPY_IMAGE); /* draw a hole */
/* allocate memory using "_16_c_need_scrn" (uses compression) */
image_c[2] = malloc(_16_c_need_scrn(10, MAXY+10, 50, 50));
image_c[3] = malloc(_16_c_need_scrn(10, MAXY+10, 50, 50));
/* save the image in the three available formats */
_16_c_save(10, MAXY+10, 50, 50, BLACK, image_c[0], FALSE, TRUE);
_16_c_save(10, MAXY+10, 50, 50, BLACK, image_c[2], FALSE, TRUE);
_16_p_save(10, MAXY+10, 50, 50, BLACK, image_p[0], FALSE, TRUE);
_16_i_save(10, MAXY+10, 50, 50, image_i[0], FALSE, TRUE);
/* make copies of the images */
_16_copy(image_c[1], image_c[0]); /* copy "c_save" image (wrst) */
_16_copy(image_c[3], image_c[2]); /* copy "c_save" image (scrn) */
_16_copy(image_p[1], image_p[0]); /* copy "p_save" image */
_16_copy(image_i[1], image_i[0]); /* copy "i_save" image */
}
/*----------------------------------------------------------------------------
* Show the images onscreen.
*/
void show_images(void)
{
int locations[9][3]; /* a two-dimensional array that will hold x, y */
/* show the images (originals and copies) */
image_c[0]->x = 10, image_c[1]->x = 100; /* set x-coordinates */
image_c[0]->y = image_c[1]->y = 150; /* set y-coordinates */
print_image_properties(10, 10, image_c[0], "image_c[0]",
"_16_c_show(10, 150, image_c[0])", locations); /* print image properties */
_16_c_show(-1, -1, image_c[0], COPY_IMAGE); /* show the original image */
_16_c_show(-1, -1, image_c[1], COPY_IMAGE); /* now show the copied image */
/* this demonstrates the usage of "-1" for the "x" value */
_16_c_show(190, 150, image_c[2], COPY_IMAGE); /* show the original image */
_16_c_show(280, 150, image_c[3], COPY_IMAGE); /* now show the copied image */
/* this demonstrates the usage of inputting the "x" value */
_16_p_show(10, 250, image_p[0], COPY_IMAGE); /* show the original image */
_16_p_show(100, 250, image_p[1], COPY_IMAGE); /* now show the copied image */
_16_i_show(10, 350, image_i[0], COPY_IMAGE); /* show the original image */
_16_i_show(100, 350, image_i[1], COPY_IMAGE); /* now show copied image */
PRINT(10, MAXY-25, message); /* print a message */
str_copy(&message[0], "images and their properties are shown -- press any \
key to return to DOS"); /* copy "image_cmnd" */
/*** the '\' character allow a string to be continued on the next line */
PRINT(10, MAXY-25, message); /* print "message" */
locations[7][0] = 10, locations[7][1] = MAXY-25,
locations[7][2] = textwidth(message); /* save text data */
getchr(); /* wait for a key press */
erase_text(locations, 9); /* restore background under text */
}
/*----------------------------------------------------------------------------
* Convert an integer into either the string "TRUE" or the string "FALSE".
*
* "boolean" - integer to check
*
* RETURNS:
* = "TRUE" if "boolean" is not equal to 0
* = "FALSE" if "boolean" is equal to 0
*/
char *t_or_f(int boolean)
{
if (boolean) return("TRUE");
else return("FALSE");
}
/*==========================================================================*/
// REALiTY
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -