Term-Gnuplot

 view release on metacpan or  search on metacpan

gnuterm/term/vgagl.trm  view on Meta::CPAN

 * 
 *  G1024x768x256,
 *  G800x600x256,
 *  G640x480x256,
 *  G320x200x256,
 *  G1280x1024x256,
 *  G1152x864x256,
 *  G1360x768x256,
 *  G1600x1200x256,
 *
 *
 * AUTHOR
 *  Johannes Zellner <johannes@zellner.org>
 *  the code is based on the `linux' driver.
 *  The first version dated January 2000.
 */

/*
 * Compile with -l3kit -lvgagl -lvga
 */

#define VGAGL_DEBUGGING
#include "driver.h"
#include "pm3d.h"

#ifdef TERM_REGISTER
register_term(vgagl)
#endif

#ifdef TERM_PROTO

#define VGAGL_VCHAR FNT5X9_VCHAR
#define VGAGL_HCHAR FNT5X9_HCHAR
#define VGAGL_VTIC 5
#define VGAGL_HTIC 5
#define VGAGL_XMAX 0		/* These two entries are just place holders. */
#define VGAGL_YMAX 0		/* The actual values will be filled in init. */

TERM_PUBLIC void VGAGL_options __PROTO((void));
TERM_PUBLIC int VGAGL_get_mode __PROTO((void));
TERM_PUBLIC void VGAGL_init __PROTO((void));
TERM_PUBLIC void VGAGL_reset __PROTO((void));
TERM_PUBLIC void VGAGL_text __PROTO((void));
TERM_PUBLIC void VGAGL_graphics __PROTO((void));
TERM_PUBLIC void VGAGL_linetype __PROTO((int linetype));
TERM_PUBLIC void VGAGL_move __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC void VGAGL_vector __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC int VGAGL_text_angle __PROTO((int ang));
TERM_PUBLIC void VGAGL_put_text_with_color __PROTO((unsigned int x, unsigned int y, const char* str, int color));
TERM_PUBLIC void VGAGL_put_text __PROTO((unsigned int x, unsigned int y, const char* str));
TERM_PUBLIC void VGAGL_suspend __PROTO((void));
TERM_PUBLIC void VGAGL_resume __PROTO((void));


#include "mousecmn.h"
void VGAGL_eventually_process_graphics_events __PROTO((void));
TERM_PUBLIC void VGAGL_draw_cursor __PROTO((int x, int y));
TERM_PUBLIC void VGAGL_set_ruler __PROTO((int, int));
TERM_PUBLIC void VGAGL_set_cursor __PROTO((int, int, int));
TERM_PUBLIC void VGAGL_put_tmptext __PROTO((int, const char str[]));
TERM_PUBLIC void VGAGL_set_clipboard __PROTO((const char[]));
TERM_PUBLIC void VGAGL_init_keytable __PROTO((void));
TERM_PUBLIC void VGAGL_xor_pixel __PROTO((int x, int y));
TERM_PUBLIC void VGAGL_xor_pixel_wrapper __PROTO((int x, int y, int color));
TERM_PUBLIC void VGAGL_hline_xor __PROTO((int x1, int x2, int y));
TERM_PUBLIC void VGAGL_vline_xor __PROTO((int y1, int y2, int x));
#if 0
TERM_PUBLIC void VGAGL_line_xor __PROTO((unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2));
#endif
TERM_PUBLIC void VGAGL_zoombox __PROTO((int x, int y));
TERM_PUBLIC void VGAGL_update_zoombox __PROTO((int x, int y));
TERM_PUBLIC void VGAGL_update_cursor __PROTO((int x, int y));
TERM_PUBLIC void VGAGL_signal_handler __PROTO((int signum));
TERM_PUBLIC void VGAGL_setpalettecolor __PROTO((int index, double red, double green, double blue));
TERM_PUBLIC void VGAGL_set_black_and_white __PROTO((void));
TERM_PUBLIC void VGAGL_set_line_colors __PROTO((void));
TERM_PUBLIC void VGAGL_putc __PROTO((unsigned int x, unsigned int y, int c, int ang, int color));
void (*VGAGL_old_handler) __PROTO((int));
#ifdef VGAGL_DEBUGGING
TERM_PUBLIC void VGAGL_write_dump_file __PROTO((void));
#endif

#define VGA_FPRINTF(x) fprintf x
#ifdef Y
#   undef Y
#endif
#define Y(y) (vgagl_lasty - y)

TERM_PUBLIC int VGAGL_make_palette __PROTO((t_sm_palette*));
TERM_PUBLIC void VGAGL_set_color __PROTO((double));
TERM_PUBLIC void VGAGL_filled_polygon __PROTO((int, gpiPoint*));

static const int VGAGL_8bit_colors = 240;
static const int pm3d_color_offset = 16; /* 0xff - VGAGL_8bit_colors + 1 */

static int VGAGL_pm3d_colors;
static int VGAGL_pm3d_colors_; /* VGAGL_pm3d_colors - 1 */
static t_sm_palette VGAGL_save_pal = {
    -1, -1, -1, -1, -1, -1, -1, -1,
    (rgb_color*) 0, -1, -1
};
static double VGAGL_gray = 0;

#ifdef VGAGL_ENABLE_TRUECOLOR
#define VGAGL_tri_colors 4096
static int VGAGL_truecolor = no;
static unsigned short VGAGL_line_cmap[0xf];
static unsigned short VGAGL_cmap[VGAGL_tri_colors];
#endif

#ifdef VGAGL_DEBUGGING
static char* VGAGL_dump_file = (char*) 0;
static unsigned char VGAGL_palette[0x100][3];
#endif

#endif /* TERM_PROTO */

#ifdef TERM_BODY

#include <signal.h>

gnuterm/term/vgagl.trm  view on Meta::CPAN

VGAGL_set_ruler(x, y)
    int x, y;
{
    if (x < 0) {
	/* erase last ruler */
	VGAGL_hline_xor(0, vgagl_lastx, Y(VGAGL_ruler_y));
	VGAGL_vline_xor(0, vgagl_lasty, VGAGL_ruler_x);
	VGAGL_ruler_x = -1;
    } else {
	VGAGL_ruler_x = x;
	VGAGL_ruler_y = y;
	VGAGL_hline_xor(0, vgagl_lastx, Y(VGAGL_ruler_y));
	VGAGL_vline_xor(0, vgagl_lasty, VGAGL_ruler_x);
    }
    VGAGL_need_update = yes;
    return;
}

TERM_PUBLIC void
VGAGL_set_cursor(c, x, y)
    int c, x, y;
{
    /* VGA_FPRINTF((stderr, "(VGAGL_set_cursor) \n")); */
    switch (c) {
	case -2: /* warp pointer */
	    /* TODO */
	    break;
	case -1: /* starting zoombox */
	    VGAGL_zoom.startx = x;
	    VGAGL_zoom.starty = Y(y);

	    VGAGL_zoom.currentx = VGAGL_zoom.startx;
	    VGAGL_zoom.currenty = VGAGL_zoom.starty;

	    VGAGL_zoombox(VGAGL_zoom.currentx, VGAGL_zoom.currenty);

	    break;
	case 0:  /* standard cross-hair cursor */
	    if (VGAGL_zoom.startx >= 0) {
		VGAGL_zoombox(VGAGL_zoom.currentx, VGAGL_zoom.currenty);
		VGAGL_zoom.startx = -1; /* turn zoom box off */
	    }
	    break;
	case 1:  /* cursor during rotation */
	    /* TODO */
	    break;
	case 2:  /* cursor during scaling */
	    /* TODO */
	    break;
	case 3:  /* cursor during zooming */
	    /* TODO */
	    break;
	default:
	    fprintf(stderr, "(VGAGL_set_cursor) %s:%d protocol error\n", __FILE__, __LINE__);
	    break;
    }
    return;
}

TERM_PUBLIC void
VGAGL_set_clipboard(s)
    const char s[];
{
    return;
}

TERM_PUBLIC int
VGAGL_make_palette(t_sm_palette *palette)
{
    /* only reallocate colors, if the color spec has changed */
    if (palette && (VGAGL_save_pal.colorFormulae < 0
	    || palette->colorFormulae != VGAGL_save_pal.colorFormulae
	    || palette->colorMode != VGAGL_save_pal.colorMode
	    || palette->formulaR != VGAGL_save_pal.formulaR
	    || palette->formulaG != VGAGL_save_pal.formulaG
	    || palette->formulaB != VGAGL_save_pal.formulaB
	    || palette->positive != VGAGL_save_pal.positive)) {
	int i, j;
#ifdef VGAGL_ENABLE_TRUECOLOR
	switch (VGAGL_truecolor) {
	    case yes:
		for (i = 0; i <= VGAGL_tri_colors; i++) {
		    VGAGL_cmap[i] = gl_rgbcolor
			((int)floor(palette->color[i].r * 255.999),
			 (int)floor(palette->color[i].g * 255.999),
			 (int)floor(palette->color[i].b * 255.999));
		    gl_trisetcolorlookup(i, VGAGL_cmap[i]);
		}
		break;
	    default:
#endif
		for (j = 0, i = pm3d_color_offset; i <= 0xff; i++, j++) {
		    VGAGL_setpalettecolor(i, palette->color[j].r,
			palette->color[j].g, palette->color[j].b);
		}
#ifdef VGAGL_ENABLE_TRUECOLOR
	}
#endif
	VGAGL_save_pal = *palette;
	return 0;
    } else {
	return VGAGL_pm3d_colors;
    }
}

/* set color for subsequent VGAGL_filled_polygon() calls. */
TERM_PUBLIC void
VGAGL_set_color(double gray)
{
    /* Note that the gray value is supplied for each vertex.
     * This is only for routines which don't draw interpolated
     * triangles. These routines should supply a negative
     * valued as corners[0].spec.gray, if they really want
     * this color to be taken. */
    int color = (gray <= 0) ? 0 : (int)(gray * VGAGL_pm3d_colors);
    if (color >= VGAGL_pm3d_colors)
	color = VGAGL_pm3d_colors_;
    current_color = pm3d_color_offset + color;
    VGAGL_gray = gray;
}

gnuterm/term/vgagl.trm  view on Meta::CPAN

	     corners[0].x, y[0], color[0], -1);
    }
}
#ifdef VGAGL_DEBUGGING
void
VGAGL_write_dump_file(void)
{
    FILE* fp;
    unsigned char* buf;
    unsigned char* bufptr;
    int x, y, index;
    char thisfile[0xff];
    static int thisfileno = 0;
    if (!VGAGL_dump_file) {
	return;
    }
    sprintf(thisfile, "%s%05d.ppm", VGAGL_dump_file, thisfileno++);
    fp = fopen(thisfile, "w");
    if (!fp) {
	free(VGAGL_dump_file);
	VGAGL_dump_file = 0;
    }
    fprintf(fp, "P6\n");
    fprintf(fp, "%d %d\n", modeinfo->width, modeinfo->height);
    fprintf(fp, "255\n");
    buf = gp_alloc(modeinfo->width * modeinfo->height * 3, "vgagl->buf");
    bufptr = buf;
    for (y = 0; y < modeinfo->height; y++) {
	for (x = 0; x < modeinfo->width; x++) {
	    index = gl_getpixel(x, y);
	    while (index < 0) {
		/* this is a kludge, as gl_getpixel() seems to 
		 * return pixels > 128 as the negative complement */
		index += 256;
	    }
	    *bufptr++ = VGAGL_palette[index][0];
	    *bufptr++ = VGAGL_palette[index][1];
	    *bufptr++ = VGAGL_palette[index][2];
	}
    }
    fwrite(buf, 3, modeinfo->width * modeinfo->height, fp);
    fclose(fp);
}
#endif

#endif

#ifdef TERM_TABLE
TERM_TABLE_START(vgagl_driver)
    "vgagl", "vgagl driver with mouse support and smooth colors",
    VGAGL_XMAX, VGAGL_YMAX, VGAGL_VCHAR, VGAGL_HCHAR,
    VGAGL_VTIC, VGAGL_HTIC, VGAGL_options, VGAGL_init, VGAGL_reset,
    VGAGL_text, null_scale, VGAGL_graphics, VGAGL_move, VGAGL_vector,
    VGAGL_linetype, VGAGL_put_text, VGAGL_text_angle,
    null_justify_text, do_point, do_arrow, set_font_null,
    0,				/* pointsize */
    TERM_CAN_MULTIPLOT, VGAGL_suspend, VGAGL_resume
    , 0, 0 /* fillbox, linewidth */
# ifdef USE_MOUSE
    , 0 /* VGAGL_waitforinput */, VGAGL_put_tmptext, VGAGL_set_ruler,
    VGAGL_set_cursor, VGAGL_set_clipboard
# endif
# ifdef PM3D
    , VGAGL_make_palette,
    0 /* VGAGL_previous_palette */,
    VGAGL_set_color,
    VGAGL_filled_polygon
# endif /* PM3D */
TERM_TABLE_END(vgagl_driver)
#undef LAST_TERM
#define LAST_TERM vgagl_driver
#endif

#ifdef TERM_HELP
START_HELP(vgagl)
"1 vgagl",
"?commands set terminal vgagl",
"?set terminal vgagl",
"?set term vgagl",
"?terminal vgagl",
"?term vgagl",
"?vgagl",
" The `vgagl` driver is a fast linux console driver with full mouse and pm3d",
" support.  It looks at the environment variable SVGALIB_DEFAULT_MODE for the",
" default mode; if not set, it uses a 256 color mode with the highest",
" available resolution.",
"",
" Syntax:",
"    set terminal vgagl \\",
"                 background [red] [[green] [blue]] \\",
"                 [uniform | interpolate] \\",
#if 0
"                 [dump \"file\"] \\",
#endif
"                 [mode]",
"",
" The color mode can also be given with the mode option. Both Symbolic",
" names as G1024x768x256 and integers are allowed. The `background` option",
" takes either one or three integers in the range [0, 255]. If only one",
" integers is supplied, it is taken as gray value for the background.",
" If three integers are present, the background gets the corresponding",
" color.",
" The (mutually exclusive) options `interpolate` and `uniform` control",
" if color interpolation is done while drawing triangles (on by default).",
#if 0
"",
" A `screen dump file` can be specified with the `dump \"file\"` option.",
" If this option is present, (i.e the dump file name is not empty) pressing",
" the key KP_Delete will write the file.  This action cannot and cannot be",
" rebound. The file is written in raw ppm (P6) format. Note that this option",
" is reset each time the `set term` command is issued.",
#endif
"",
" To get high resolution modes, you will probably have to modify the",
" configuration file of libvga, usually /etc/vga/libvga.conf.  Using",
" the VESA fb is a good choice, but this needs to be compiled in the",
" kernel.",
"",
" The vgagl driver uses the first *available* vga mode from the following list:",
"  - the driver which was supplied when setting vgagl, e.g. `set term vgagl",
"    G1024x768x256` would first check, if the G1024x768x256 mode is available.",



( run in 0.910 second using v1.01-cache-2.11-cpan-2398b32b56e )