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

📄 ui_svga.c

📁 另一个分形程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  *     XaoS, a fast portable realtime fractal zoomer  *                  Copyright (C) 1996,1997 by * *      Jan Hubicka          (hubicka@paru.cas.cz) *      Thomas Marsh         (tmarsh@austin.ibm.com) * * 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., 675 Mass Ave, Cambridge, MA 02139, USA. */#include "aconfig.h"#ifdef SVGA_DRIVER#include <stdio.h>#include <malloc.h>#include <vga.h>#include <vgagl.h>#include <vgamouse.h>#include <vgakeyboard.h>#include <sys/stat.h>#include <sys/types.h>#include <fcntl.h>#include <string.h>#include <unistd.h>#include "keytables.h"#include <ui.h>#include <xthread.h>#include <stdlib.h>extern int euid, egid;struct ui_driver svga_driver;static char keys[128];static int initialised;static int mode = -1;static vga_modeinfo *info;static int width = 640, height = 480;static int svga_currentbuff = 0;static double bbytesperpixel;static int colors;static int defmode = -1;static GraphicsContext screen;static GraphicsContext buffers[2];static int mousetype = NORMALMOUSE;static int retrace;static int grayscale;void *font = NULL;static int whitecolor;static int blackcolor;static voidsvga_mousetype (int m){  mousetype = m;}static voidsvga_print (int x, int y, CONST char *text){  if (colors != 2)    {      gl_setcontext (&screen);      gl_enableclipping ();      if (y > height - svga_driver.textheight)	return;      gl_write (x, y / svga_driver.textheight * 8, text);    }}static voiddraw_mouse (int x, int y, int clear){  static int oldx, oldy;  if (mousetype != REPLAYMOUSE)    {      if (x < 3)	x = 3;      if (y < 3)	y = 3;      if (x > width - 5)	x = width - 5;      if (y > height - 5)	y = height - 5;      if ((oldx != x || oldy != y) && clear)	{	  gl_setcontext (&buffers[svga_currentbuff]);	  gl_enableclipping ();	  if (mode == G320x240x256	      || mode == G320x400x256 || mode == G360x480x256)	    gl_copyscreen (&screen);	  else	    gl_copyboxtocontext (oldx - 3, oldy - 3, 8, 8, &screen, oldx - 3,				 oldy - 3);	}      /* This part is responsible for drawing an X arrow.          Honza has cut it but it is too difficult to use	 XaoS in SVGA mode if no arrow appears. */      vga_setcolor (whitecolor);      vga_drawline (x - 3, y - 3, x + 3, y + 3);      vga_drawline (x - 3, y + 3, x + 3, y - 3);      vga_setcolor (blackcolor);      vga_drawline (x + 1 - 3, y - 3, x + 1 + 3, y + 3);      vga_drawline (x + 1 - 3, y + 3, x + 1 + 3, y - 3);      /* End of drawing an X arrow. */            oldx = x;      oldy = y;    }}static voidsvga_display (void){  gl_setcontext (&buffers[svga_currentbuff]);  if (retrace)    vga_waitretrace ();  gl_copyscreen (&screen);  draw_mouse (mouse_getx (), mouse_gety (), 0);}static voidsvga_setpalette (ui_palette pal, int start, int end){  int i;  vga_waitretrace ();  for (i = 0; i < end - start; i++)    {      vga_setpalette (i + start,		      pal[i][0] >> 2, pal[i][1] >> 2, pal[i][2] >> 2);    }}static voidsvga_setgrayscale (void){  int i;  vga_waitretrace ();  for (i = 0; i < 256; i++)    {      vga_setpalette (i, i >> 2, i >> 2, i >> 2);    }}static voidsvga_flip_buffers (void){  svga_currentbuff ^= 1;}static voidhandler (int scancode, int press){  keys[scancode] = press;  if (press)    {      switch (scancode)	{	case SCANCODE_CURSORBLOCKUP:	  ui_key (UIKEY_UP);	  break;	case SCANCODE_CURSORBLOCKLEFT:	  ui_key (UIKEY_LEFT);	  break;	case SCANCODE_CURSORBLOCKDOWN:	  ui_key (UIKEY_DOWN);	  break;	case SCANCODE_CURSORBLOCKRIGHT:	  ui_key (UIKEY_RIGHT);	  break;	case 1:	  ui_key (UIKEY_ESC);	  break;	case SCANCODE_BACKSPACE:	  ui_key (UIKEY_BACKSPACE);	  break;	case SCANCODE_HOME:	  ui_key (UIKEY_HOME);	  break;	case SCANCODE_END:	  ui_key (UIKEY_END);	  break;	case SCANCODE_PAGEUP:	  ui_key (UIKEY_PGUP);	  break;	case SCANCODE_PAGEDOWN:	  ui_key (UIKEY_PGDOWN);	  break;	default:	  if (keys[SCANCODE_LEFTSHIFT] || keys[SCANCODE_RIGHTSHIFT])	    ui_key (shift_table[scancode]);	  else	    ui_key (plain_table[scancode]);	}    }}#ifdef HAVE_PTHREAD_SIGHANDLERextern void pthread_sighandler (int sig);static voidshutdown (int n){  printf ("Task cancelled\n");  pthread_exit (NULL);}#endifstatic voidinit_mode (void){  int i, high;  while (mode == -1)    {      printf ("Choose one of the following video modes: \n");      high = 0;      for (i = 1; i <= GLASTMODE; i++)	if (vga_hasmode (i))	  {	    char expl[100];	    char *cols = NULL;	    *expl = '\0';	    info = vga_getmodeinfo (i);	    if (info->colors != 256 && info->colors != 32768		&& info->colors != 65536 && info->colors != 16777216)	      continue;	    if (i == G320x200x256)	      strcpy (expl, "packed-pixel");	    else if (i == G320x240x256		     || i == G320x400x256 || i == G360x480x256)	      strcpy (expl, "Mode X");	    else	      strcpy (expl, "packed-pixel, banked");	    if (info->flags & IS_INTERLACED)	      {		if (*expl != '\0')		  strcat (expl, ", ");		strcat (expl, "interlaced");	      }	    if (info->flags & IS_DYNAMICMODE)	      {		if (*expl != '\0')		  strcat (expl, ", ");		strcat (expl, "dynamically loaded");	      }	    high = i;	    if (defmode == -1)	      {		printf ("%5d: %dx%d, ", i, info->width, info->height);		if (cols == NULL)		  printf ("%d", info->colors);		else		  printf ("%s", cols);		printf (" colors ");		if (*expl != '\0')		  printf ("(%s)", expl);		printf ("\n");	      }	  }      if (defmode == -1)	{	  printf ("Enter mode number (1-%d): ", high);	  fflush (stdout);	  scanf ("%d", &mode);	  getchar ();	  printf ("\n");	}      else	mode = defmode, defmode = -1;      if (mode < 1 || mode > GLASTMODE)	{	  printf ("Error: Mode number out of range \n");	  mode = -1;	  continue;	}      if (!vga_hasmode (mode))	{	  printf ("Error: Video mode not supported by driver\n");	  mode = -1;	  continue;	}      info = vga_getmodeinfo (mode);      if (info->colors != 256 && info->colors != 32768	  && info->colors != 65536 && info->colors != 16777216)	{	  printf	    ("Error: Only 256,32768,65536 and 16777216 color modes supported\n");	  mode = -1;	  continue;	}    }  colors = info->colors;  bbytesperpixel = info->bytesperpixel;  if (info->colors == 2)    bbytesperpixel = 1.0 / 8;  if (!bbytesperpixel)    bbytesperpixel = 1;  width = info->width;  height = info->height;#ifdef HAVE_PTHREAD_SIGHANDLER  if (nthreads != 1)    {      printf ("You are starting threaded XaoS. Everything should work well,\n"	      "except console switching, wich is broken because of SIGUSR\n"	      "collision between linuxthreads and SVGAlib\n"	      "\n"	      "DONT EVEN THINK ABOUT TOUCHING ALT+FKEY COMBINATION!\n"	      "\n"	      "Result is blocked keyboard. You need to kill XaoS from the net then\n\n"	      "Attempts for console switch (from other programs etc) may also cause\n"	      "confusion in thread synchronization! or even kill some of XaoS processes\n"	      "and cause lockup in main control loop. So do NOT try to start X or\n"	      "some other bad thinks. Be curefull.\n\n"	      "For your own safety switching of consoles will be blocked\n"	      "Please press enter to continue/ctrl+c to abort\n");

⌨️ 快捷键说明

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