📄 ui_aa.c
字号:
#include "aconfig.h"#ifdef AA_DRIVER#include <string.h>#include <malloc.h>#include <aalib.h>#include <ui.h>#include <unistd.h>#include <xmenu.h>#include <archaccel.h>struct ui_driver aalib_driver;static aa_palette palette;static aa_palette aapalette;static int useaapalette;#define c contextstatic aa_context *c;static unsigned char *secondary;static int mouse;static int nomouse;static void aa_build_menus (void);static void aa_remove_menus (void);extern unsigned char *aa_chardata;extern unsigned char *aa_colordata;extern int aa_cursorx, aa_cursory;static voidaa_print (int x, int y, CONST char *text){ aa_puts (c, x / 2, y / 2, AA_SPECIAL, text);}static voidaa_display (void){ int i; aa_renderpalette (c, useaapalette ? aapalette : palette, &aa_defrenderparams, 0, 0, aa_scrwidth (c), aa_scrheight (c)); for (i = 0; i < aa_scrwidth (c) * aa_scrheight (c); i++) { if (aa_colordata[i] != 255) aa_text (c)[i] = aa_chardata[i], aa_attrs (c)[i] = aa_colordata[i]; }}static voidaa_set_palette (ui_palette pal, int start, int end){ int i; for (i = start; i <= end; i++) aa_setpalette (palette, i, pal[i - start][0], pal[i - start][1], pal[i - start][2]); aa_display (); aa_flush (c);}static voidaa_flip_buffers (void){ unsigned char *tmp; tmp = secondary; secondary = c->imagebuffer; c->imagebuffer = tmp;}static voidaa_free_buffers (char *b1, char *b2){ free (aa_chardata); free (aa_colordata); free (secondary);}static intaa_alloc_buffers (char **b1, char **b2){ secondary = malloc (aa_imgwidth (c) * aa_imgheight (c)); *(unsigned char **) b2 = secondary; *(unsigned char **) b1 = c->imagebuffer; aa_chardata = malloc (aa_scrwidth (c) * aa_scrheight (c)); aa_colordata = malloc (aa_scrwidth (c) * aa_scrheight (c)); return aa_imgwidth (c); /* bytes per scanline */}static voidaa_getsize (int *w, int *h){ aa_resize (c); *w = aa_imgwidth (c); *h = aa_imgheight (c);}static int mousex, mousey, mouseb;static voidaa_processevents (int wait, int *mx, int *my, int *mb, int *k){ int ch; static int keys; do { if ((ch = aa_getevent (c, wait)) != AA_NONE && ch != AA_MOUSE && ch != AA_RESIZE && ch < 256) ui_key (ch); switch (ch) { case AA_BACKSPACE: ui_key (UIKEY_BACKSPACE); break; case AA_ESC: ui_key (UIKEY_ESC); break; case AA_RESIZE: ui_resize (); break; case AA_MOUSE: aa_getmouse (c, &mousex, &mousey, &mouseb); break; case AA_LEFT: ui_key (UIKEY_LEFT); if (c->kbddriver->flags & AA_SENDRELEASE) keys |= 1; break; case AA_LEFT | AA_RELEASE: keys &= ~1; break; case AA_RIGHT: ui_key (UIKEY_RIGHT); if (c->kbddriver->flags & AA_SENDRELEASE) keys |= 2; break; case AA_RIGHT | AA_RELEASE: keys &= ~2; break; case AA_UP: ui_key (UIKEY_UP); if (c->kbddriver->flags & AA_SENDRELEASE) keys |= 4; break; case AA_UP | AA_RELEASE: keys &= ~4; break; case AA_DOWN: ui_key (UIKEY_DOWN); if (c->kbddriver->flags & AA_SENDRELEASE) keys |= 8; break; case AA_DOWN | AA_RELEASE: keys &= ~8; break; } wait = 0; } while (ch != AA_NONE); *mx = mousex * 2; *my = mousey * 2; *k = keys; *mb = 0; if (mouseb & AA_BUTTON1) *mb |= BUTTON1; if (mouseb & AA_BUTTON2) *mb |= BUTTON2; if (mouseb & AA_BUTTON3) *mb |= BUTTON3; return;}#define NATTRS 7static char *aadriver = NULL;static char *kbddriver = NULL;static char *mousedriver = NULL;static char *deffont = NULL;static int width, height, minwidth, minheight, maxwidth, maxheight, recwidth, recheight;static int enable[NATTRS + 2], disable[NATTRS + 2];static int extended, inverse, bright = 0, contrast = 0;static float aa_gamma, dimmul, boldmul;static int dithering[3];static int randomval = 0;static int masks[] = { AA_NORMAL_MASK, AA_DIM_MASK, AA_BOLD_MASK, AA_BOLDFONT_MASK, AA_REVERSE_MASK, AA_ALL, AA_EIGHT};#ifdef DESTICKYextern int euid, egid;#endifstatic intaa_initialize (void){ int i, y; aa_parseoptions (NULL, NULL, NULL, NULL); /*parse environment first */ if (deffont != NULL) { for (y = 0; aa_fonts[y] != NULL; y++) { if (!strcmp (deffont, aa_fonts[y]->name) || !strcmp (deffont, aa_fonts[y]->shortname)) { aa_defparams.font = aa_fonts[y]; break; } } } if (extended) aa_defparams.supported |= AA_EXTENDED; for (i = 0; i < NATTRS; i++) { if (enable[i]) aa_defparams.supported |= masks[i]; if (disable[i]) aa_defparams.supported &= ~masks[i]; } for (i = 0; i < 3; i++) if (dithering[i]) aa_defrenderparams.dither = i; if (randomval) aa_defrenderparams.randomval = randomval; if (bright) aa_defrenderparams.bright = bright; if (contrast) aa_defrenderparams.contrast = contrast; if (aa_gamma) aa_defrenderparams.gamma = aa_gamma; if (width) aa_defparams.width = width; if (height) aa_defparams.height = height; if (minwidth) aa_defparams.minwidth = minwidth; if (minheight) aa_defparams.minheight = minheight; if (maxwidth) aa_defparams.maxwidth = maxwidth; if (maxheight) aa_defparams.maxheight = maxheight; if (recwidth) aa_defparams.recwidth = recwidth; if (recheight) aa_defparams.recheight = recheight; if (aadriver != NULL) aa_recommendhidisplay (aadriver); if (kbddriver != NULL) aa_recommendhikbd (kbddriver); if (mousedriver != NULL) aa_recommendhimouse (mousedriver); if (dimmul) aa_defparams.dimmul = dimmul; if (boldmul) aa_defparams.boldmul = boldmul; if (inverse) aa_defrenderparams.inversion = 1;#ifdef DESTICKY seteuid (euid); /* We need supervisor rights to open mouse. */ setegid (egid);#endif c = aa_autoinit (&aa_defparams);#ifdef DESTICKY seteuid (getuid ()); /* Don't need supervisor rights anymore. */ setegid (getgid ());#endif if (c == NULL) return 0; aa_autoinitkbd (c, AA_SENDRELEASE); if (!nomouse) mouse = aa_autoinitmouse (c, AA_MOUSEALLMASK); aalib_driver.width = aa_mmwidth (c) / 10.0; aalib_driver.height = aa_mmheight (c) / 10.0; aa_build_menus (); return (1);}static voidaa_uninitialise (void){ aa_close (c); aa_remove_menus ();}static voidaa_get_mouse (int *x, int *y, int *b){ if (mouse) aa_getmouse (c, &mousex, &mousey, &mouseb); *x = mousex * 2; *y = mousey * 2; *b = 0; if (mouseb & AA_BUTTON1) *b |= BUTTON1; if (mouseb & AA_BUTTON2) *b |= BUTTON2; if (mouseb & AA_BUTTON3) *b |= BUTTON3;}static voidaa_mousetype (int type){#if (AA_LIB_VERSION>1||AA_LIB_MINNOR>0) if (type == REPLAYMOUSE) aa_hidemouse (c); else aa_showmouse (c);#endif}#if AA_LIB_VERSION==1 && AA_LIB_MINNOR==0#define SUPPORTED c->driver->params.supported#else#define SUPPORTED c->driverparams.supported#endifstatic int driver;static int font;static int mask;static voidaa_save5 (void){ struct aa_hardware_params p = aa_defparams; struct aa_context *sc; struct aa_savedata data; int i; char *name; char extension[100]; if (aa_formats[driver]->flags & AA_USE_PAGES) strcpy (extension, "_0_0"); else extension[0] = 0; strcat (extension, aa_formats[driver]->extension);#ifdef DJGPP name = ui_getfile ("fr", extension); /*fit into ugly 8char. limit */#else name = ui_getfile ("fract", extension);#endif if (name == NULL) { aa_print (0, 0, "Save driver initialization failed"); aa_flush (c); sleep (3); return; } for (i = 0; name[i] != '.' && name[i] != '_'; i++); name[i] = 0; strcat (name, "%c%e"); p.minwidth = p.maxwidth = 0; p.minheight = p.maxheight = 0; p.width = aa_scrwidth (c); p.height = aa_scrheight (c);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -