⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 !best003.c

📁 supplementary source file 1 for The BESTLibrary
💻 C
📖 第 1 页 / 共 2 页
字号:
/*==========================================================================
 *
 *  !BEST003.C                                       Tuesday, April 12, 1994
 *
 *  640x480x16 graphics mode windows routines
 *  supplementary source file 3 for The BESTLibrary
 *
 *  Authored independently by George Vanous
 *
 *==========================================================================*/


/* ------------------------------------------------------------------------ */
/* ----------------------------  INCLUDE FILES  --------------------------- */

#include <alloc.h>
#include <stdlib.h>
#include <graphics.h>
#include "!bestlib.h"                  // include !BESTLIB.H in compilation

/* ------------------------------------------------------------------------ */
/* -------------------------  GLOBAL DEFINITIONS  ------------------------- */

extern mousedata msdata;
extern asciiscan key;
extern char *textstring;

/* ------------------------------------------------------------------------ */


/*----------------------------------------------------------------------------
 * Pop up a column in 640x480x16 graphics mode.
 *
 * [see !BESTLIB.DOC for a description of each parameter]
 * [see !BESTLIB.DOC for a description of the return values]
 */
int _16_popupcolumn(int x, int y, int choice, int maxmenus, char *ptr[], int ms)
{
  #define MAXDATA 20	                  // maximum number of menu options
  #define BORDERTHICKNESS 3            // thickness of border in pixels
  #define BORDERCOLOR YELLOW           // color of surrounding border
  #define INNERXSPACE 3                // space between left border and text
  #define INNERYSPACE 2                // space between top border and text
  #define INTERSPACE 33                // space between horizontal submenus
  #define INNERCOLOR BLUE              // inner color of menu
  #define FILLSTYLE 1                  // fill pattern of inner menu
  #define TEXTCOLOR YELLOW             // color of text
  #define INACTIVECOLOR LIGHTRED       // color of inactive text
  #define BARCOLOR WHITE               // color of choosebar
  int barx, bary,
      barlength,
      flength, fheight,
      textx, texty,
      height = 0, length = 0;
  imagedata *menubg;
  register int i, ii;

  choice--;
  for (i = 0; i < maxmenus; i++) {
    if (textwidth(ptr[i]) > length) length = textwidth(ptr[i]);
    if (textheight(ptr[i]) > height) height = textheight(ptr[i]);
  }
  height++;
  fheight = height * maxmenus + BORDERTHICKNESS * 2 + INNERYSPACE * 2,
  flength = length + BORDERTHICKNESS * 2 + INNERXSPACE * 2;
  if ((menubg = (void *) malloc(_16_i_need(flength, fheight))) == NULL)
    return(-1);                        // return code for error
  _16_i_save(x, y, flength, fheight, menubg, FALSE, TRUE);
  for (i = 0; i < BORDERTHICKNESS; i++)
    _16_boxoutline(x + i, y + i, flength - i - i, fheight - i - i, BORDERCOLOR, COPY_IMAGE);

  _16_boxfill(x + i, y + i, flength - i - i, fheight - i - i, BLACK, COPY_IMAGE);
  textx = x + BORDERTHICKNESS + INNERXSPACE,
  texty = y + BORDERTHICKNESS + INNERYSPACE;
  setfillstyle(FILLSTYLE, INNERCOLOR);
  floodfill(textx, texty, BORDERCOLOR);
  setcolor(TEXTCOLOR);
  for (ii = texty - 1, i = 0; i < maxmenus; ii += height, i++)
    outtextxy(textx, ii, ptr[i]);
  barlength = length + INNERXSPACE * 2,
  fheight -= BORDERTHICKNESS,
  barx = textx - INNERXSPACE,
  bary = texty + choice * height;

  if (ms) {
    msdata.pos[0] = msdata.npos[0] = MAXX / 2,
    msdata.pos[1] = msdata.npos[1] = MAXY / 2;
    ms_set(msdata.pos[0], msdata.pos[1]);
  }
 while (TRUE)
 {
   _16_boxfill(barx, bary, barlength, height, BARCOLOR, XOR_IMAGE);
   key.ascii = key.scan = 0;
   if (ms) while (TRUE) {
     if (keyhit()) {
       getchr();
       break;
     }
     ms_stat();
     if (msdata.buts[0] != msdata.nbuts[0]) {
       msdata.buts[0] = msdata.nbuts[0];
       if (!msdata.nbuts[0]) { key.ascii = 13; break; }
     }
     if (msdata.buts[1] != msdata.nbuts[1]) {
       msdata.buts[1] = msdata.nbuts[1];
       if (!msdata.nbuts[1]) { key.ascii = 27; break; }
     }
     if (abs(length = msdata.npos[0] - msdata.pos[0]) > 40) {
       if (length > 0) key.scan = 'M';
       else key.scan = 'K';
       msdata.pos[0] = msdata.npos[0] = MAXX / 2,
       msdata.pos[1] = msdata.npos[1] = MAXY / 2;
       ms_set(msdata.pos[0], msdata.pos[1]);
       break;
     }
     if (abs(length = msdata.npos[1] - msdata.pos[1]) > 10) {
       if (length > 0) key.scan = 'P';
       else key.scan = 'H';
       msdata.pos[0] = msdata.npos[0] = MAXX / 2,
       msdata.pos[1] = msdata.npos[1] = MAXY / 2;
       ms_set(msdata.pos[0], msdata.pos[1]);
       break;
     }
   }
   else
     getchr();
   _16_boxfill(barx, bary, barlength, height, BARCOLOR, XOR_IMAGE);
   if (key.ascii == 9 || key.ascii == 13 || key.ascii == 27) {
     if (key.ascii == 9 || key.ascii == 27) choice = -1;
     break;
   }                                   // 'H' = 1, 'P' = 4
   if (key.scan == 'H') {
     if (--choice < 0) choice = maxmenus - 1, bary = texty + height * (maxmenus - 1);
     else bary -= height;
   }
   else if (key.scan == 'P') {
     if (++choice == maxmenus) choice = 0, bary = texty;
     else bary += height;
   }
 }
  _16_i_show(x, y, menubg, COPY_IMAGE);
  free(menubg);
  return(++choice);
}

/*----------------------------------------------------------------------------
 * Pop up a menu in 640x480x16 graphics mode.
 *
 * [see !BESTLIB.DOC for a description of each parameter]
 * [see !BESTLIB.DOC for a description of the return values]
 */
int _16_popupmenu(int x, int y, int choice, int maxmenus, char *ptr[], int data[][3], char *text[], int ms)
{
  #define MAXDATA 20                  // maximum number of menu options
  #define BORDERTHICKNESS 3           // thickness of border in pixels
  #define BORDERCOLOR YELLOW          // color of surrounding border
  #define INNERXSPACE 3               // space between left border and text
  #define INNERYSPACE 2               // space between top border and text
  #define INTERSPACE 33               // space between horizontal submenus
  #define INNERCOLOR BLUE             // inner color of menu
  #define FILLSTYLE 1                 // fill pattern of inner menu
  #define TEXTCOLOR YELLOW            // color of text
  #define INACTIVECOLOR LIGHTRED      // color of inactive text
  #define BARCOLOR WHITE              // color of choosebar
  int datalength[MAXDATA] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
  int a, b, bgx, bgy, bx, barx, bary, barlength, choicex = 0,
      length, flength, height, fheight, textx, texty;
  imagedata *bg, *bg2, *menubg;
  register int i, ii;

  choice--;
  for (a = i = 0; i < maxmenus; i++) {
    for (ii = 0; ii < data[i][0]; ii++) {
      if (!data[i][1])
        datalength[i] = 0;
      else
        datalength[i] += textwidth( text[ data[i][1] + ii] ) + INTERSPACE;
    }
    if (datalength[i] > a)
      a = datalength[i];
  }
  for (b = i = ii = 0; i < maxmenus; i++) {
    if (textwidth(ptr[i]) > ii)
      ii = length = textwidth(ptr[i]);
    if (textheight(ptr[i]) > b)
      b = height = textheight(ptr[i]);
  }
  height++;
  bg = (void *) malloc(_16_i_need(a + BORDERTHICKNESS * 2, height + BORDERTHICKNESS * 2 + INNERYSPACE * 2));
  bg2 = (void *) malloc(_16_i_need(BORDERTHICKNESS, height + BORDERTHICKNESS * 2 + INNERYSPACE * 2));
  fheight = height * maxmenus + BORDERTHICKNESS * 2 + INNERYSPACE * 2,
  flength = length + BORDERTHICKNESS * 2 + INNERXSPACE * 2;
  menubg = (void *) malloc(_16_i_need(flength, fheight));
  if (menubg == NULL || bg2 == NULL || bg == NULL) {
    if (bg != NULL) free(bg);
    if (bg2 != NULL) free(bg2);
    if (menubg != NULL) free(menubg);
    return(-1);                        // return code for error
  }
  _16_i_save(x, y, flength, fheight, menubg, FALSE, TRUE);
  for (i = 0; i < BORDERTHICKNESS; i++)
    _16_boxoutline(x + i, y + i, flength - i - i, fheight - i - i, BORDERCOLOR, COPY_IMAGE);

  _16_boxfill(x + i, y + i, flength - i - i, fheight - i - i, BLACK, COPY_IMAGE);
  textx = x + BORDERTHICKNESS + INNERXSPACE,
  texty = y + BORDERTHICKNESS + INNERYSPACE;
  setfillstyle(FILLSTYLE, INNERCOLOR);
  floodfill(textx, texty, BORDERCOLOR);
  setcolor(TEXTCOLOR);
  for (b = texty - 1, i = 0, ii = 0x0001; i < maxmenus; b += height, i++, ii = ii << 1) {
    if (ii & (unsigned int)text[0])
      setcolor(TEXTCOLOR);
    else
      setcolor(INACTIVECOLOR);
    outtextxy(textx, b, ptr[i]);
  }
  setcolor(TEXTCOLOR);

  barlength = length + INNERXSPACE * 2,
  fheight -= BORDERTHICKNESS,
  barx = textx - INNERXSPACE,
  bary = texty + choice * height;

  for (i = ii = 1; i < choice + 1; i++) ii = ii << 1;
  for (i = 0; i < maxmenus; i++, ii = ii << 1, bary += height, choice++)
    if (ii & (unsigned int)text[0]) break;
  if (i == maxmenus) return(-1);

  bgx = barx + barlength + BORDERTHICKNESS,
  bgy = bary - BORDERTHICKNESS - INNERYSPACE,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -