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

📄 _msdos.c

📁 数据类型和算法库LEDA 数据类型和算法库LEDA
💻 C
📖 第 1 页 / 共 3 页
字号:
/*******************************************************************************
+
+  LEDA  3.0
+
+
+  _msdos.c
+
+
+  Copyright (c) 1992  by  Max-Planck-Institut fuer Informatik
+  Im Stadtwald, 6600 Saarbruecken, FRG     
+  All rights reserved.
+ 
*******************************************************************************/



#ifdef __TURBOC__
#include <alloc.h>
#endif

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <dos.h>

#include "msdos.h"

#if defined(GNUDOS)
static int   getch() { return getkey(); }
#endif

#define KEY_UP 72
#define KEY_DO 80
#define KEY_LE 75
#define KEY_RI 77

#define BG_COLOR 0
#define FG_COLOR 1
#define PANEL_BG_COLOR 1
#define PANEL_FG_COLOR 0


#define XPIX(coord) (int)(xorigin + (coord)*x_draw_scale)
#define YPIX(coord) (int)(yorigin - (coord)*y_draw_scale)

#define XREAL(pix)  ((double)(pix-xorigin)/x_draw_scale)
#define YREAL(pix)  ((double)(yorigin-pix)/y_draw_scale)


static char default_frame_label[128];

static char frame_label[80];

static char read_frame_format[] = "%8.2f %8.2f      %s";

static int mouse_installed;

typedef void (*PRD)();
typedef void (*PMA)();

static void x_draw_mouse_default_action(x,y) 
double x,y;
{ /* do nothing */}


PRD x_draw_redraw = 0;

static int xpix_mode_op;

static int xdots,ydots, xorigin,yorigin;  /* pixels          */

static int mouse_key,mouse_xpix, mouse_ypix; 
static int mouse_last_xpix, mouse_last_ypix;
static int mouse_start_xpix, mouse_start_ypix;  /* start for segments  ... */
static int mouse_read_kind;


static double mouse_xreal,mouse_yreal;
static double mouse_last_xreal,mouse_last_yreal;
static double mouse_start_xreal,mouse_start_yreal;

static double x_draw_aspect_ratio;
static double y_draw_scale;   

static char* mesg_list[24];
static int   mesg_count;



/* external variables */

int x_draw_window_xpos = 0;
int x_draw_window_ypos = 0;
int x_draw_window_width = 0;
int x_draw_window_height = 0;
   
double x_draw_xmax,x_draw_xmin,x_draw_ymax,x_draw_ymin, x_draw_scale;

int    x_draw_grid_mode;
int    x_draw_depth;

int    x_draw_line_width, x_draw_node_width, x_draw_line_style, x_draw_color,
       x_draw_text_mode, x_draw_drawing_mode, x_draw_screen_flush;



void x_draw_flush() { }

void x_draw_set_show_coord() { }

void x_draw_set_redraw(f)
PRD f;
{ x_draw_redraw = f; 
 }

void x_draw_set_frame_label(message)
char* message;
{ int save = x_draw_set_mode(1);
  put_text(20,1,frame_label,0);
  strcpy(frame_label,message);
  put_text(20,1,frame_label,0);
  x_draw_set_mode(save);
  }

void x_draw_reset_frame_label() 
{ x_draw_set_frame_label(default_frame_label); }


void x_draw_mouse_segment_action(x,y)
double x,y;
{ set_color(FG_COLOR);
  line(mouse_start_xpix,mouse_start_ypix,XPIX(x),YPIX(y));
 }

void x_draw_mouse_rect_action(x,y)
double x,y;
{ set_color(FG_COLOR);
  rectangle(mouse_start_xpix, mouse_start_ypix, XPIX(x),YPIX(y));
 } 


void x_draw_mouse_circle_action(x,y)
double x,y;
{ double r = hypot(x - mouse_start_xreal, y - mouse_start_yreal);
  set_color(FG_COLOR);
  circle(mouse_start_xpix,mouse_start_ypix,(int)(r*x_draw_scale));
 }


void x_draw_set_font(fname)
char* fname;
{ }



/*
from <LEDA/window.h>:
enum color  { white=0, black=1,  red=2,    green=3, 
              blue=4,  yellow=5, violet=6, orange=7 };
*/

static void x_draw_set_color(col)
int col;
{ set_color(col); }

int x_draw_set_line_width(w)
int w;
{ int save = x_draw_line_width;
  x_draw_line_width = w;
  set_line_style(x_draw_line_style,x_draw_line_width);
  return save;
}


int x_draw_set_line_style(s)
int s;
{ int old = x_draw_line_style;
  x_draw_line_style = s;
  set_line_style(s,x_draw_line_width);
  return old;
}


int x_draw_set_mode(m)
int m;
{ int old=get_mode();
  set_mode(m);
  return old;
}


int x_draw_set_node_width(w)
int w;
{ int save = x_draw_node_width;
  x_draw_node_width = w;
  return save;
 }

int x_draw_set_text_mode(m)
int m;
{ int save = x_draw_text_mode;
  x_draw_text_mode = m;
  return save;
 }


static void draw_cursor(x,y)
int x,y;
{ int save = get_color();
  int dx = 8;
  int dy = 8*x_draw_aspect_ratio;
  set_color(1);
  set_line_style(0,3);
  line(x-dx,y,x+dx,y);
  line(x,y-dy,x,y+dy);
  set_line_style(x_draw_line_style,x_draw_line_width);
  set_color(save);
 }

int x_draw_get_button()
{ char c;
  int taste = 0;
  union REGS regs;
  union REGS key_regs;

  if (kbhit())  /* keyboard */
  { c=getch();
    switch(c) {
        case    13:
        case    '1': taste = 1; break; 
        case    '2': taste = 2; break;
        case    '3': taste = 3; break;
        case    '!': taste = -1; break;
        case    '@': taste = -2; break;
        case    '#': taste = -3; break;
        case    '4': taste = 4; break;
        case    '5': taste = 5; break;
        case    '6': taste = 6; break;
        case    27 : exit_graphics(); exit(0); break;     /* escape */
       }
    }
  
    if (mouse_installed)
    { if (taste==0)
      { regs.x.ax=03;
        int86(0x33,&regs,&regs);
        switch (regs.x.bx) {
        case 1:  taste = 1; break;
        case 2:  taste = 3; break;
        case 4:  taste = 2; break;
        }
        if (taste!=0)
        { key_regs.h.ah=0x02;
          int86(0x16,&key_regs,&key_regs);
          if (key_regs.h.al & 3) taste = -taste;    /* shift key */
          if (key_regs.h.al & 4) taste += 3;        /* ctrl key  */
         }
       }

      while (regs.x.bx != 0)
      { regs.x.ax=03;
        int86(0x33,&regs,&regs);
       }
     }
  return taste;
}
  

int x_read_mouse_action(action, xstart,ystart,x,y)
PMA   action;
double xstart;
double ystart;
double *x;
double *y;
{ 
  int  taste=0;
  char c=0;
  int  save_mode;
  int  save_line_width;
  int  step;
  
  union REGS regs, key_regs;

  if (action==0)
    action = x_draw_mouse_default_action; 

  save_mode = x_draw_set_mode(1);
  save_line_width = x_draw_set_line_width(1);

  mouse_start_xreal = xstart;
  mouse_start_yreal = ystart;
  mouse_start_xpix = XPIX(xstart);
  mouse_start_ypix = YPIX(ystart);

  action(mouse_last_xreal,mouse_last_yreal);

  draw_cursor(mouse_last_xpix, mouse_last_ypix);


  while (taste == 0)
  { 
    if (kbhit())  /* keyboard */
    { c=getch();
      step = 8;
      key_regs.h.ah=0x02;
      int86(0x16,&key_regs,&key_regs);
      if (key_regs.h.al & 3) step = 1;    /* shift key */
      switch(c) {
        case KEY_LE: mouse_xpix -= step; break;
        case KEY_RI: mouse_xpix += step; break;
        case KEY_UP: mouse_ypix -= step*x_draw_aspect_ratio; break;
        case KEY_DO: mouse_ypix += step*x_draw_aspect_ratio; break;
        case    13:  /* return */
        case    '1': taste = 1; break;
        case    '2': taste = 2; break;
        case    '3': taste = 3; break;
        case    '!': taste = -1; break;
        case    '@': taste = -2; break;
        case    '#': taste = -3; break;
        case    '4': taste = 4; break;
        case    '5': taste = 5; break;
        case    '6': taste = 6; break;
        case    27 : exit_graphics(); exit(0); break;     /* escape */
       }
      regs.x.ax=04;
      regs.x.cx=mouse_xpix;
      regs.x.dx=mouse_ypix;
      int86(0x33,&regs,&regs);
     }
  
    if (mouse_installed && taste==0)
    { regs.x.ax=03;
      int86(0x33,&regs,&regs);
      switch (regs.x.bx) {
      case 1:  taste = 1; break;
      case 4:  taste = 2; break;
      case 2:  taste = 3; break;
      }
      mouse_xpix=regs.x.cx;
      mouse_ypix=regs.x.dx;

      if (taste!=0)
      { key_regs.h.ah=0x02;
        int86(0x16,&key_regs,&key_regs);
        if (key_regs.h.al & 3) taste = -taste;    /* shift key */
        if (key_regs.h.al & 4) taste += 3;        /* ctrl key  */
       }
     }
  
    mouse_xreal =  XREAL(mouse_xpix);
    mouse_yreal =  YREAL(mouse_ypix);
   
    if (x_draw_grid_mode) 
    { mouse_xreal = x_draw_grid_mode * (int)(mouse_xreal/x_draw_grid_mode + ((mouse_xreal > 0) ? 0.5 : -0.5));
   
      mouse_yreal = x_draw_grid_mode * (int)(mouse_yreal/x_draw_grid_mode + ((mouse_yreal > 0) ? 0.5 : -0.5));
   
      mouse_xpix  = XPIX(mouse_xreal);
      mouse_ypix  = YPIX(mouse_yreal);
    }
          
    if (mouse_last_xpix != mouse_xpix || mouse_last_ypix != mouse_ypix)
    { action(mouse_last_xreal,mouse_last_yreal);
      action(mouse_xreal,mouse_yreal);
      draw_cursor(mouse_last_xpix,mouse_last_ypix);
      draw_cursor(mouse_xpix,mouse_ypix);
     }

    mouse_last_xpix = mouse_xpix;
    mouse_last_ypix = mouse_ypix;
          
    mouse_last_xreal = mouse_xreal;
    mouse_last_yreal = mouse_yreal;

   }

   if (mouse_installed)
     while (regs.x.bx != 0)
     { regs.x.ax=03;
       int86(0x33,&regs,&regs);
      }

   draw_cursor(mouse_xpix,mouse_ypix);

   action(mouse_xreal,mouse_yreal);

   
  *x = mouse_xreal;
  *y = mouse_yreal;

 x_draw_set_mode(save_mode);
 x_draw_set_line_width(save_line_width);

 if (c=='s') taste = -taste;
 if (c=='c') taste =  taste + 3;

 return taste;

}


int x_read_mouse(kind, xstart,ystart,x,y)
int    kind;   /* 0: point, 1: segment, 2:rectangle, 3: circle */
double xstart;
double ystart;
double *x;
double *y;
{ 
  PMA f;
  int key;

  switch(kind) {

  case 0 : f =  x_draw_mouse_default_action;
          break;

  case 1:  f = x_draw_mouse_segment_action;
           break;

  case 2:  f = x_draw_mouse_rect_action;
           break;

  case 3:  f = x_draw_mouse_circle_action;
           break;

  default: f = x_draw_mouse_default_action;
           break;

  }

  key = x_read_mouse_action(f,xstart,ystart,x,y);

  return key;

}



void x_draw_init_window(w_width,w_height,w_xpos,w_ypos,label)
int w_width;
int w_height;
int w_xpos;
int w_ypos;
char* label;
{ 
  int  i;
  union REGS regs;
  int err;

  init_graphics();
  clear_screen();

 /* init mouse driver */
   regs.x.ax=0;
   int86(0x33,&regs,&regs);

  mouse_installed = (regs.x.ax == 0x0ffff);

  strcpy(default_frame_label,frame_label);
  if (label)
      strcpy(frame_label,label);
  else
      frame_label[0] = '\0';

  x_draw_depth = 1;

  x_draw_set_line_style(0);
  x_draw_set_line_width(1);
  x_draw_set_mode(0);
  x_draw_set_node_width(10);
  x_draw_set_text_mode(0); 

  x_draw_color = FG_COLOR;

  x_draw_xmin = 0;
  x_draw_ymin = 0;
  x_draw_xmax = 0;
  x_draw_ymax = 0;
  x_draw_scale = 1;
  y_draw_scale = 1;

  mouse_xpix = 0;
  mouse_ypix = 0;
  mouse_last_xpix = 0;
  mouse_last_ypix = 0;

  x_draw_aspect_ratio = get_xy_ratio();

  if (!mouse_installed) 
   x_draw_acknowledge("No mouse: use cursor keys");

}


⌨️ 快捷键说明

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