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

📄 utils.c

📁 C++游戏开发书籍的实例非常适合初学但又又想往游戏开发方面发展的人学习哦
💻 C
📖 第 1 页 / 共 5 页
字号:
 *           scroll horizontally if we're not at beginning of line.
 */
int  move_left( WINDOW *window )
{
int  new_ruler = FALSE;

   if (window->ccol > window->start_col) {
      show_ruler_char( window );
      --window->ccol;
      --window->rcol;
   } else if (window->ccol == window->start_col && window->rcol > 0) {
      --window->rcol;
      --window->bcol;
      window->file_info->dirty = LOCAL;
      new_ruler = TRUE;
   }
   sync( window );
   if (new_ruler) {
      make_ruler( window );
      show_ruler( window );
   }
   return( OK );
}


/*
 * Name:    move_right
 * Purpose: To move the cursor right one character
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   If the cursor is already at the right of the screen (logical
 *          column 80) then scroll horizontally right.
 */
int  move_right( WINDOW *window )
{
int  new_ruler = FALSE;

   if (window->rcol < g_display.line_length - 1) {
      if (window->ccol < window->end_col) {
         show_ruler_char( window );
         ++window->ccol;
         ++window->rcol;
      } else if (window->ccol == window->end_col) {
         ++window->rcol;
         ++window->bcol;
         window->file_info->dirty = LOCAL;
         new_ruler = TRUE;
      }
   }
   sync( window );
   if (new_ruler) {
      make_ruler( window );
      show_ruler( window );
   }
   return( OK );
}


/*
 * Name:    pan_left
 * Purpose: To pan the screen left one character
 * Date:    January 5, 1992
 * Passed:  window:  pointer to current window
 */
int  pan_left( WINDOW *window )
{
/*
 * if (window->bcol == 0) {
 *    if (window->ccol > window->start_col) {
 *       show_ruler_char( window );
 *       --window->ccol;
 *       --window->rcol;
 *    }
 * } else if (window->bcol > 0 ) {
 * * *  Scroll window left function:
 * * *      --window->bcol;
 * * *      if (window->ccol < g_display.ncols - 1)
 * * *         ++window->ccol;
 * * *      else
 * * *         --window->rcol;
 */
   if (window->bcol > 0 ) {
      --window->bcol;
      --window->rcol;
      window->file_info->dirty = LOCAL;
      make_ruler( window );
      show_ruler( window );
   }
   sync( window );
   return( OK );
}


/*
 * Name:    pan_right
 * Purpose: To pan the screen right one character
 * Date:    January 5, 1992
 * Passed:  window:  pointer to current window
 */
int  pan_right( WINDOW *window )
{
   if (window->rcol < g_display.line_length - 1) {
/*
 *      scroll screen right function:
 *      if (window->ccol > 0)
 *         --window->ccol;
 *      else
 *         ++window->rcol;
 */
      ++window->rcol;
      ++window->bcol;
      window->file_info->dirty = LOCAL;
      make_ruler( window );
      show_ruler( window );
   }
   sync( window );
   return( OK );
}


/*
 * Name:    word_left
 * Purpose: To move the cursor left one word
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   Words are considered strings of letters, numbers and underscores,
 *          which must be separated by other characters.
 */
int  word_left( WINDOW *window )
{
text_ptr p;             /* text pointer */
int  len;               /* length of current line */
int  rc;
register int rcol;
long rline;
line_list_ptr ll;
WINDOW w;

   entab_linebuff( );
   if (un_copy_line( window->ll, window, TRUE ) == ERROR)
      return( ERROR );
   rc = OK;
   dup_window_info( &w, window );
   rline = window->rline;
   rcol  = window->rcol;
   ll = window->ll;
   if (ll->len != EOF) {
      p = ll->line;
      len = ll->len;

      if (p != NULL  &&  rcol > 0  &&  rcol >= len  &&
                                      !myiswhitespc( *(p + len - 1) )) {
         rcol = len - 1;
         p += rcol;
         for (; rcol >= 0 && !myiswhitespc( *p ); rcol--, p--);
         ++rcol;
         check_virtual_col( window, rcol, rcol );
         make_ruler( window );
         show_ruler( window );
      } else {
         rcol = rcol >= len ? len-1 : rcol;
         if (rcol >= 0)
            p += rcol;
         if (p != NULL  &&  rcol > 0  &&  !myiswhitespc( *p )  &&
                                          !myiswhitespc( *(p-1) )) {
            for (; rcol >= 0 && !myiswhitespc( *p ); rcol--, p--);
            ++rcol;
            check_virtual_col( window, rcol, rcol );
            make_ruler( window );
            show_ruler( window );
         } else {

            /*
             * if we are on the first letter of a word, get off.
             */
            if (p != NULL)
               for (; rcol >= 0 && !myiswhitespc( *p ); rcol--, p--);

            /*
             * go to the next line if word begins at 1st col in line.
             */
            if (rcol < 0) {
               if (ll->prev != NULL) {
                  --rline;
                  ll = ll->prev;
                  p = ll->line;
                  rcol = ll->len - 1;
                  if (rcol >= 0)
                     p += rcol;
               } else
                  rc = ERROR;
            }

            /*
             * skip all blanks until we get to a previous word
             */
            while (rc == OK  &&  (p == NULL  ||  (p != NULL  &&
                                                  myiswhitespc( *p )))) {
               for (; rcol >= 0 && myiswhitespc( *p ); rcol--, p--);
               if (rcol < 0) {
                  if (ll->prev != NULL) {
                     --rline;
                     ll = ll->prev;
                     p = ll->line;
                     rcol = ll->len - 1;
                     if (rcol >= 0)
                        p += rcol;
                  } else
                     rc = ERROR;
               } else
                  break;
            }

            /*
             * now, find the beginning of the word.
             */
            if (rc == OK  &&  p != NULL) {
               for (; rcol >= 0 && !myiswhitespc( *p ); rcol--, p--);
               bin_offset_adjust( window, rline );
               find_adjust( window, ll, rline, rcol+1 );
               if (rline != w.rline && !window->file_info->dirty) {
                  update_line( &w );
                  show_curl_line( window );
               }
               make_ruler( window );
               show_ruler( window );
            } else
               rc = ERROR;
         }
      }
   } else
      rc = ERROR;

   sync( window );
   return( rc );
}


/*
 * Name:    word_right
 * Purpose: To move the cursor right one word
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   Words are considered strings of letters, numbers and underscores,
 *           which must be separated by other characters.
 */
int  word_right( WINDOW *window )
{
int  len;               /* length of current line */
text_ptr p;             /* text pointer */
int  rc;
WINDOW w;
register int rcol;
line_list_ptr ll;
long rline;

   entab_linebuff( );
   if (un_copy_line( window->ll, window, TRUE ) == ERROR)
      return( ERROR );
   rc = OK;
   dup_window_info( &w, window );
   rline = window->rline;
   rcol  = window->rcol;
   ll = window->ll;
   if (ll->len != EOF) {
      p = ll->line;
      len = ll->len;

      /*
       * if rcol is past EOL, move it to EOL
       */
      rcol = rcol >= len ? len-1 : rcol;
      if (rcol >= 0)
         p += rcol;

      /*
       * if cursor is on a word, find end of word.
       */
      if (p != NULL)
         for (; rcol < len && !myiswhitespc( *p ); rcol++, p++);
      else
         rcol = len;

      /*
       * go to the next line if word ends at eol.
       */
      if (rcol == len) {
         ++rline;
         ll = ll->next;
         if (ll->len != EOF) {
            p = ll->line;
            len = ll->len;
            rcol = 0;
         } else
            rc = ERROR;
      }

      /*
       * now, go forward thru the file looking for the first letter of word.
       */
      while (rc == OK && (p == NULL  ||  (p != NULL && myiswhitespc( *p )))) {
         for (; rcol < len && myiswhitespc( *p ); rcol++, p++);
         if (rcol == len) {
            ++rline;
            ll = ll->next;
            if (ll->len != EOF) {
               p = ll->line;
               len = ll->len;
               rcol = 0;
            } else
               rc = ERROR;
         } else
            break;
      }
   } else
      rc = ERROR;

   if (rc == OK) {
      bin_offset_adjust( window, rline );
      find_adjust( window, ll, rline, rcol );
      make_ruler( window );
      show_ruler( window );
   }

   if (rline != w.rline && !window->file_info->dirty) {
      update_line( &w );
      show_curl_line( window );
   }
   sync( window );
   return( rc );
}


/*
 * Name:    next_dirty_line
 * Purpose: To move the cursor to the next dirty line, if it exists
 * Date:    April 1, 1993
 * Passed:  window:  pointer to current window
 */
int  next_dirty_line( WINDOW *window )
{
int  rc;
line_list_ptr ll;
long rline;
long bin_offset;       /* binary offset */
WINDOW w;

   entab_linebuff( );
   if (un_copy_line( window->ll, window, TRUE ) == ERROR)
      return( ERROR );
   rc = OK;
   dup_window_info( &w, window );
   rline = window->rline;
   ll = window->ll;
   bin_offset = window->bin_offset;
   if (ll->len != EOF) {
      while (rc == OK) {
         if (ll->len != EOF) {
            ++rline;
            bin_offset += ll->len;
            ll = ll->next;
            if (ll->dirty == TRUE)
               break;
         } else
            rc = ERROR;
      }
   } else
      rc = ERROR;

   if (rc == OK) {
      window->bin_offset = bin_offset;
      find_adjust( window, ll, rline, window->rcol );
      make_ruler( window );
      show_ruler( window );
   } else
      error( WARNING, window->bottom_line, utils16 );

   if (rline != w.rline && !window->file_info->dirty) {
      update_line( &w );
      show_curl_line( window );
   }
   sync( window );
   return( rc );
}


/*
 * Name:    prev_dirty_line
 * Purpose: To move the cursor to the prev dirty line, if it exists
 * Date:    April 1, 1993
 * Passed:  window:  pointer to current window
 */
int  prev_dirty_line( WINDOW *window )
{
int  rc;
line_list_ptr ll;
long rline;
long bin_offset;        /* binary offset */
WINDOW w;

   entab_linebuff( );
   if (un_copy_line( window->ll, window, TRUE ) == ERROR)
      return( ERROR );
   rc = OK;
   dup_window_info( &w, window );
   rline = window->rline;
   ll = window->ll;
   bin_offset = window->bin_offset;
   if (ll->prev != NULL) {
      while (rc == OK) {
         if (ll->prev != NULL) {
            --rline;
            ll = ll->prev;
            bin_offset -= ll->len;
            if (ll->dirty == TRUE)
               break;
         } else
            rc = ERROR;
      }
   } else
      rc = ERROR;

   if (rc == OK) {
      window->bin_offset = bin_offset;
      find_adjust( window, ll, rline, window->rcol );
      make_ruler( window );
      show_ruler( window );
   } else
      error( WARNING, window->bottom_line, utils16 );

   if (rline != w.rline && !window->file_info->dirty) {
      update_line( &w );
      show_curl_line( window );
   }
   sync( window );
   return( rc );
}


/*
 * Name:    center_window
 * Purpose: To place the current line or cursor in the center of a window.
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 */
int  center_window( WINDOW *window )
{
int  center;
int  center_line;
int  diff;
register file_infos *file;
register WINDOW *win;           /* put window pointer in a register */

   win = window;
   file = win->file_info;
   center = (win->bottom_line + 1 - win->top_line) / 2 - win->ruler;
   center_line = win->top_line + win->ruler + center;
   diff = center_line - win->cline;
   entab_linebuff( );
   if (un_copy_line( win->ll, win, TRUE ) == ERROR)
      return( ERROR );
   if (g_status.command == CenterWindow) {
      if (diff > 0) {
         if (win->rline + diff <= file->length) {
            upd

⌨️ 快捷键说明

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