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

📄 text_dialog.hpp

📁 本程序是主要是扫雷
💻 HPP
字号:
/*     Copyright(c) Ben Bear 2003-2004  *///  This program is free software; you can redistribute it and/or//  modify it under the terms of the GNU General Public License as//  published by the Free Software Foundation; either version 2 of the//  License, or (at your option) any later version.//  //  This program is distributed in the hope that it will be useful,//  but WITHOUT ANY WARRANTY; without even the implied warranty of//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU//  General Public License for more details.//  //  You should have received a copy of the GNU General Public License//  along with this program; if not, write to the Free Software//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA//  02111-1307, USA.#ifndef __text_dialog_hpp#define __text_dialog_hpp#include <curses.h>#include "buf_text.hpp"class text_dialog{private:  static const int TEXT_WIDTH = 76;  static const int TEXT_HEIGHT = 20;private:  buf_text buf;  WINDOW *dialog;  int dlg_h, dlg_w;  const char* dlg_name;  WINDOW *win_text;  WINDOW *win_btn;  int ok_x;  short pair_f, pair_b;private:  bool new_dialog ();  void del_dialog ();  bool show ();  void page_show ();  void per_show ();public:  text_dialog (const char* name, const char* text)    : dlg_name(name), buf(text, TEXT_HEIGHT, TEXT_WIDTH)  {    if (new_dialog () == false)      return;    show ();    del_dialog ();  }};booltext_dialog::new_dialog (){  dlg_h = TEXT_HEIGHT + 3;  dlg_w = TEXT_WIDTH + 2;  int scr_h, scr_w;  getmaxyx (stdscr, scr_h, scr_w);  dialog = newwin (dlg_h, dlg_w,		   (scr_h - dlg_h)/2, (scr_w - dlg_w)/2);  keypad (dialog, TRUE);  wattron (dialog, A_REVERSE);  box (dialog, 0, 0);    win_text = derwin (dialog, TEXT_HEIGHT, TEXT_WIDTH, 1, 1);  keypad (win_text, TRUE);  wattron (win_text, A_REVERSE);  page_show ();  win_btn = derwin (dialog, 1, TEXT_WIDTH, TEXT_HEIGHT+1, 1);  keypad (win_btn, TRUE);    if (has_colors())    {      pair_content (1, &pair_f, &pair_b);      init_pair (1, COLOR_GREEN, COLOR_BLUE);      wattron (win_btn, COLOR_PAIR(1));    }  wattroff (win_btn, A_REVERSE);  char tmp[10];  ok_x = TEXT_WIDTH/3*2;  mvwhline (win_btn, 0, 0, '-', ok_x);  sprintf (tmp, ": %%s :");  mvwprintw (win_btn, 0, 1, tmp, dlg_name);  sprintf (tmp, "%%%ds", dlg_w-2-4-strlen(dlg_name));  wprintw (win_btn, tmp, "");  wattron (win_btn, A_REVERSE);  mvwprintw (win_btn, 0, ok_x, "< OK >");  wattroff (win_btn, A_REVERSE);    per_show ();  touchwin (dialog);  wrefresh (dialog);  return true;}voidtext_dialog::del_dialog (){  if (has_colors())    init_pair (1, pair_f, pair_b);  delwin (win_btn);  delwin (win_text);  wclear (dialog);  wrefresh (dialog);  delwin (dialog);}booltext_dialog::show (){  int ch;  do    {      wmove (dialog, TEXT_HEIGHT+1, ok_x+3);      ch = wgetch (dialog);      int dir;      switch (ch)	{	case KEY_UP:	  dir = buf_text::BUF_LINE_UP;	  break;	case KEY_DOWN:	  dir = buf_text::BUF_LINE_DOWN;	  break;	case KEY_LEFT:	case KEY_PPAGE:	  dir = buf_text::BUF_PAGE_UP;	  break;	case KEY_RIGHT:	case KEY_NPAGE:	  dir = buf_text::BUF_PAGE_DOWN;	  break;	case KEY_HOME:	  dir = buf_text::BUF_BEGIN;	  break;	case KEY_END:	  dir = buf_text::BUF_END;	  break;	default:	  continue;	  break;	}      if (buf.move (dir) == false)	beep ();      else	{	  page_show ();	  per_show ();	  touchwin (dialog);	  wrefresh (dialog);	}    }  while (ch != '\n');  return true;}voidtext_dialog::page_show (){  const char* *page = new (const char*)[TEXT_HEIGHT];  int lines = buf.get_cur_page (page);  char tmp[10];  sprintf (tmp, "%%-%ds", TEXT_WIDTH);  int i = 0;  for (; i < lines; ++i)    mvwprintw (win_text, i, 0, tmp, page[i]);  for (; i < TEXT_HEIGHT; ++i)    mvwprintw (win_text, i, 0, tmp, "");  delete[] page;}voidtext_dialog::per_show (){  int x = TEXT_WIDTH - 10;  int per = buf.get_per ();  char str[12];  if (per == -1)    sprintf (str, "- Top -");  else if (per == 100)    sprintf (str, "- Bottom -");  else    sprintf (str, "- %d%% -", per);  mvwprintw (win_btn, 0, x, "%-10s", str);}#endif

⌨️ 快捷键说明

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