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

📄 small_menu.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 __small_menu_hpp#define __small_menu_hpp#include <string.h>#include <stdio.h>#include <curses.h>int menu_select (const char* name, const char** items){  WINDOW *win;  WINDOW *der;  int item_h = 0;		// height of menu items  int item_w = 0;		// width of menu items  int win_h, win_w;  int win_y, win_x;  int name_len = strlen(name);  int ch;  char tmp[8];  noecho ();  for (; items[item_h] != 0;)    {      int len = strlen(items[item_h]);      if (item_w < len)	item_w = len;      ++item_h;    }  win_h = item_h + 2;  win_w = item_w + 3;  if (win_w < name_len+4)    win_w = name_len+4;  getmaxyx (stdscr, win_y, win_x);  win_y = (win_y - win_h) / 4;  win_x = (win_x - win_w) / 4;  win = newwin (win_h, win_w, win_y, win_x);  keypad (win, TRUE);  der = derwin (win, win_h-2, win_w-2, 1, 1);  keypad (der, TRUE);  box (win, 0, 0);  mvwprintw (win, 0, (win_w - name_len - 2) / 2,	     " %s ", name);  sprintf (tmp, " %%-%ds", win_w-3);  for (int i = 0; i < item_h; ++i)    mvwprintw (win, i+1, 1, tmp, items[i]);  int cur_s = 0;  int new_s;  wmove (der, cur_s, 1);  wchgat (der, win_w-3, A_REVERSE, 0, NULL);  touchwin (win);  wrefresh (win);  do    {      new_s = cur_s;      wmove (win, cur_s+1, 1);      ch = wgetch (win);      switch (ch)	{	case KEY_UP:	  new_s = (new_s + item_h - 1) % item_h;	  break;	case KEY_DOWN:	  new_s = (new_s + 1) % item_h;	  break;	case '\n':	  continue;		/* continue do...while */	  break;	}      if (new_s != cur_s)	{	  wmove (der, cur_s, 1);	  wchgat (der, win_w-3, A_NORMAL, 0, NULL);	  cur_s = new_s;	  wmove (der, cur_s, 1);	  wchgat (der, win_w-3, A_REVERSE, 0, NULL);	  touchwin (win);	  wrefresh (win);	}    }  while (ch != '\n');    wclear (win);  wrefresh (win);  delwin (der);  delwin (win);  return cur_s;}#endif

⌨️ 快捷键说明

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