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

📄 utils.c

📁 C++游戏开发书籍的实例非常适合初学但又又想往游戏开发方面发展的人学习哦
💻 C
📖 第 1 页 / 共 5 页
字号:
      temp[color] = '\0';
   color = g_display.eof_color;
   window_eol_clear( window, color );
   s_output( temp, window->cline, window->start_col, color );
}


/*
 * Name:    display_current_window
 * Purpose: display text in current window
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   use a temporary window structure, "w", to do the dirty work.
 */
void display_current_window( WINDOW *window )
{
int  count;     /* number of lines updated so far */
int  number;    /* number of lines visible in window */
register int i; /* register variable */
WINDOW w;       /* scratch window structure */
int  curl;      /* current line on screen, window->cline */
int  eof;

   /*
    * initialize the scratch variables
    */
   number = window->bottom_line - ((window->top_line + window->ruler) - 1);
   count  = window->cline - (window->top_line + window->ruler);
   dup_window_info( &w, window );

   w.cline -= count;
   w.rline -= count;
   for (eof=count; eof > 0; eof--)
      w.ll = w.ll->prev;


   /*
    * start at the top of the window and display a window full of text
    */
   eof = FALSE;
   curl = window->cline;
   for (i=number; i>0; i--) {
      if (w.ll->len != EOF) {
         /*
          * if this is window->cline, do not show the line because we
          *  show the curl at the end of this function.  don't show it twice
          */
         if (w.cline != curl)
            update_line( &w );
         w.ll = w.ll->next;
      } else if (eof == FALSE) {
         show_eof( &w );
         eof = TRUE;
      } else
         window_eol_clear( &w, COLOR_TEXT );
      ++w.cline;
      ++w.rline;
   }
   show_asterisk( window );
   show_curl_line( window );
}


/*
 * Name:    redraw_screen
 * Purpose: display all visible windows, modes, and headers
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 */
int  redraw_screen( WINDOW *window )
{
register WINDOW *above;        /* window above current */
register WINDOW *below;        /* window below current */

   cls( );
   /*
    * display the current window
    */
   redraw_current_window( window );

   /*
    * now update all the other windows
    */
   above = below = window;
   while (above->prev || below->next) {
      if (above->prev) {
         above = above->prev;
         redraw_current_window( above );
      }
      if (below->next) {
         below = below->next;
         redraw_current_window( below );
      }
   }
   window->file_info->dirty = FALSE;
   show_modes( );
   return( OK );
}


/*
 * Name:    redraw_current_window
 * Purpose: redraw all info in window
 * Date:    July 13, 1991
 * Passed:  window:  pointer to current window
 */
void redraw_current_window( WINDOW *window )
{

   /*
    * display the current window
    */
   if (window->visible) {
      display_current_window( window );
      show_window_header( window );
      show_ruler( window );
      show_ruler_pointer( window );
      if (window->vertical)
         show_vertical_separator( window );
   }
}


/*
 * Name:    show_changed_line
 * Purpose: Only one line was changed in file, just show it
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 */
void show_changed_line( WINDOW *window )
{
WINDOW *above;                  /* window above current */
WINDOW *below;                  /* window below current */
WINDOW w;                       /* scratch window structure */
long changed_line;              /* line number in file that was changed */
long top_line, bottom_line;     /* top and bottom line in file on screen */
int  line_on_screen;            /* is changed line on screen? */
file_infos *file;               /* file pointer */

   file = window->file_info;
   if ((file->dirty == LOCAL || file->dirty == GLOBAL) && window->visible)
      show_curl_line( window );
   changed_line = window->rline;

   /*
    * now update the line in all other windows
    */
   if (file->dirty != LOCAL) {
      above = below = window;
      while (above->prev || below->next) {
         if (above->prev) {
            above = above->prev;
            dup_window_info( &w, above );
         } else if (below->next) {
            below = below->next;
            dup_window_info( &w, below );
         }

         /*
          * is this window the changed file and is it visible?
          */
         if (w.file_info == file && w.visible) {

            /*
             * calculate file lines at top and bottom of screen.
             * the changed line may not be the curl in other windows.
             */
            line_on_screen = FALSE;
            top_line = w.rline - (w.cline - (w.top_line + w.ruler));
            bottom_line = w.rline + (w.bottom_line - w.cline);
            if (changed_line == w.rline)
               line_on_screen = CURLINE;
            else if (changed_line < w.rline && changed_line >= top_line) {
               line_on_screen = NOTCURLINE;
               while (w.rline > changed_line) {
                  w.ll = w.ll->prev;
                  --w.rline;
                  --w.cline;
               }
            } else if (changed_line > w.rline && changed_line <= bottom_line) {
               line_on_screen = NOTCURLINE;
               while (w.rline < changed_line) {
                  w.ll = w.ll->next;
                  ++w.rline;
                  ++w.cline;
               }
            }

            /*
             * display the changed line if on screen
             */
            if (line_on_screen == NOTCURLINE)
               update_line( &w );
            else if (line_on_screen == CURLINE)
               show_curl_line( &w );
         }
      }
   }
   file->dirty = FALSE;
}


/*
 * Name:    show_curl_line
 * Purpose: show current line in curl color
 * Date:    January 16, 1992
 * Passed:  window:  pointer to current window
 */
void show_curl_line( WINDOW *window )
{
int  text_color;
int  dirty_color;

   if (window->visible  &&  g_status.screen_display) {
      text_color = g_display.text_color;
      dirty_color = g_display.dirty_color;
      g_display.dirty_color = g_display.text_color = g_display.curl_color;
      update_line( window );
      g_display.text_color = text_color;
      g_display.dirty_color = dirty_color;
   }
}


/*
 * Name:    dup_window_info
 * Purpose: Copy window info from one window pointer to another
 * Date:    June 5, 1991
 * Passed:  dw: destination window
 *          sw: source window
 */
void dup_window_info( WINDOW *dw, WINDOW *sw )
{
   memcpy( dw, sw, sizeof( WINDOW ) );
}


/*
 * Name:    adjust_windows_cursor
 * Purpose: A change has been made, make sure pointers are not ahead of
 *           or behind file.
 * Date:    June 5, 1991
 * Passed:  window:       pointer to current window
 *          line_change:  number of lines add to or subtracted from file
 * Notes:   If a file has been truncated in one window and there is another
 *           window open to the same file and its current line is near the
 *           end, the current line is reset to the last line of the file.
 */
void adjust_windows_cursor( WINDOW *window, long line_change )
{
register WINDOW *next;
long i;
file_infos *file;
MARKER *marker;
long length;

   file = window->file_info;
   length = file->length;
   next = g_status.window_list;
   while (next != NULL) {
      if (next != window) {
         if (next->file_info == file) {
            if (next->rline > length + 1) {
               next->rline = length;
               next->ll    = file->line_list_end;
               file->dirty = NOT_LOCAL;
            } else if (next->rline < 1) {
               next->rline = 1;
               next->cline = next->top_line + next->ruler;
               next->ll    = file->line_list;
               next->bin_offset = 0;
               file->dirty = NOT_LOCAL;
            }
            if (next->rline > window->rline  &&  line_change) {
               file->dirty = NOT_LOCAL;
               if (line_change < 0) {
                  for (i=line_change; i < 0 && next->ll->next != NULL; i++) {
                     next->bin_offset += next->ll->len;
                     next->ll = next->ll->next;
                  }
               } else if (line_change > 0) {
                  for (i=line_change; i > 0 && next->ll->prev != NULL; i--) {
                     next->ll = next->ll->prev;
                     next->bin_offset -= next->ll->len;
                  }
               }
            }
            if (next->rline < (next->cline -(next->top_line+next->ruler-1))) {
               next->cline = (int)next->rline+(next->top_line+next->ruler)-1;
               file->dirty = NOT_LOCAL;
            }
         }
      }
      next = next->next;
   }

   /*
    * now adjust any markers.
    */
   for (i=0; i<3; i++) {
      marker = &file->marker[ (int) i ];
      if (marker->rline > window->rline) {
         marker->rline += line_change;
         if (marker->rline < 1L)
            marker->rline = 1L;
         else if (marker->rline > length)
            marker->rline = length;
      }
   }
}


/*
 * Name:    first_non_blank
 * Purpose: To find the column of the first non-blank character
 * Date:    June 5, 1991
 * Passed:  s:    the string to search
 *          len:  length of string
 * Returns: the first non-blank column
 */
int  first_non_blank( text_ptr s, int len )
{
register int count = 0;

   if (s != NULL) {
      if (mode.inflate_tabs) {
         for (; len > 0 && (*s == ' ' || *s == '\t'); s++, len--) {
            if (*s != '\t')
               ++count;
            else
               count += mode.ptab_size - (count % mode.ptab_size);
         }
      } else {
         while (len-- > 0  &&  *s++ == ' ')
           ++count;
      }
   }
   return( count );
}


/*
 * Name:    find_end
 * Purpose: To find the last character in a line
 * Date:    October 31, 1992
 * Passed:  s:    the string to search
 *          len:  length of string
 * Returns: the first non-blank column
 */
int  find_end( text_ptr s, int len )
{
register int count = 0;

   if (s != NULL) {
      if (mode.inflate_tabs) {
         for (;len > 0; s++, len--) {
            if (*s == '\t')
               count += mode.ptab_size - (count % mode.ptab_size);
            else
               ++count;
         }
      } else
         count = len;
   }
   return( count );
}


/*
 * Name:    is_line_blank
 * Purpose: is line empty or does it only contain spaces?
 * Date:    November 28, 1991
 * Passed:  s:    the string to search
 *          len:  length of string
 * Returns: TRUE if line is blank or FALSE if something is in line
 */
int is_line_blank( text_ptr s, int len )
{
   if (s != NULL) {
      if (mode.inflate_tabs) {
        while (len > 0  &&  (*s == ' ' || *s == '\t')) {
           ++s;
           --len;
        }
      } else {
         while (len > 0  &&  *s == ' ') {
            ++s;
            --len;
         }
      }
   } else
      len = 0;
   return( len == 0 );
}


/*
 * Name:    page_up
 * Purpose: To move the cursor one page up the window
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   The cursor line is moved back the required number of lines
 *           towards the start of the file.
 *          If the start of the file is reached, then movement stops.
 */
int  page_up( WINDOW *window )
{
int  i;                 /* count of lines scanned */
int  rc = OK;           /* default return code */
register WINDOW *win;   /* put window pointer in a register */
long number;
long len;

   win = window;
   entab_linebuff( );
   if (un_copy_line( win->ll, win, TRUE ) == ERROR)
      return( ERROR );
   if (win->rline != (win->cline - (win->top_line + win->ruler - 1))) {
      i = win->cline - (win->top_line + win->ruler - 1);
      number = win->rline;
      if (( win->rline - i) < win->page)
         win->rline = (win->cline-(win->top_line + win->ruler -1)) + win->page;
      win->rline -= win->page;
      for (len =0, i=(int)(number - win->rline); i>0; i--)
         if (win->ll->prev != NULL) {
            win->ll = win->ll->prev;
            len -= win->ll->len;
         }
      win->file_info->dirty = LOCAL;
      win->bin_offset += len;
   } else
      rc = ERROR;
   sync( win );
   return( rc );
}


/*
 * Name:    page_down
 * Purpose: To move the cursor one page down the window
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   The cursor line is moved forwards the required number of lines
 *           towards the end of the file.
 *          If the end of the file is reached, then movement stops.
 */
int  page_down( WINDOW *window )
{
int  i;                 /* count of lines scanned so far */
int  k;
int  rc = OK;
long len;
register WINDOW *win;  /* put window pointer in a register */
line_list_ptr p;

   win = window;
   entab_linebuff( );
   if (un_copy_line( win->ll, win, TRUE ) == ERROR)
      return( ERROR );
   p = win->ll;
   k = win->cline - (win->top_line + win->ruler);
   for (len=i=0; i < win->page && p->next != NULL; i++, k++, p=p->next)
      if (p->len != EOF)
         len += p->len;
   if (k >= win->page) {

⌨️ 快捷键说明

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