Пример #1
0
static void redraw(struct GP_Context *context)
{
	GP_Pixel white_pixel, black_pixel;

	black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, context);
	white_pixel = GP_RGBToContextPixel(0xff, 0xff, 0xff, context);

	GP_Fill(context, black_pixel);
	GP_Line(context, 0, 0, context->w - 1, context->h - 1, white_pixel);
	GP_Line(context, 0, context->h - 1, context->w - 1, 0, white_pixel);
}
Пример #2
0
void redraw_screen(void)
{
    SDL_LockSurface(display);

    GP_Fill(&context, black_pixel);

    GP_Text(&context, NULL, W/2, 20, GP_ALIGN_CENTER | GP_VALIGN_BELOW,
            darkgray_pixel, black_pixel, "GFXprim SDL Demo");

    GP_Line(&context, 0, 0, W-1, H-1, darkgray_pixel);
    GP_Line(&context, 0, H-1, W-1, 0, darkgray_pixel);

    SDL_UnlockSurface(display);
}
Пример #3
0
static void redraw(GP_Backend *backend)
{
	GP_Context *context = backend->context;

	/* Now draw some testing patters */
	black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, context);
	white_pixel = GP_RGBToContextPixel(0xff, 0xff, 0xff, context);
	red_pixel   = GP_RGBToContextPixel(0xff, 0x00, 0x00, context);
	blue_pixel  = GP_RGBToContextPixel(0x00, 0x00, 0xff, context);
	green_pixel = GP_RGBToContextPixel(0x00, 0xff, 0x00, context);

	GP_Fill(context, white_pixel);

	unsigned int i, j;
	for (i = 0; i < 40; i++) {
		GP_HLineXYW(context, 0, i, i, black_pixel);
		GP_HLineXYW(context, 1, i + 40, i, black_pixel);
		GP_HLineXYW(context, 2, i + 80, i, black_pixel);
		GP_HLineXYW(context, 3, i + 120, i, black_pixel);
		GP_HLineXYW(context, 4, i + 160, i, black_pixel);
		GP_HLineXYW(context, 5, i + 200, i, black_pixel);
		GP_HLineXYW(context, 6, i + 240, i, black_pixel);
		GP_HLineXYW(context, 7, i + 280, i, black_pixel);
	}

	for (i = 0; i < 256; i++) {
		for (j = 0; j < 256; j++) {
			uint8_t val = 1.00 * sqrt(i*i + j*j)/sqrt(2) + 0.5;

			GP_Pixel pix = GP_RGBToContextPixel(i, j, val, context);
			GP_PutPixel(context, i + 60, j + 10, pix);
		}
	}

	GP_Text(context, NULL, 60, 270, GP_VALIGN_BELOW|GP_ALIGN_RIGHT,
	        black_pixel, white_pixel, "Lorem Ipsum dolor sit...");

	GP_Text(context, NULL, 60, 290, GP_VALIGN_BELOW|GP_ALIGN_RIGHT,
	        red_pixel, white_pixel, "Lorem Ipsum dolor sit...");

	GP_Text(context, NULL, 60, 310, GP_VALIGN_BELOW|GP_ALIGN_RIGHT,
	        green_pixel, white_pixel, "Lorem Ipsum dolor sit...");

	GP_Text(context, NULL, 60, 330, GP_VALIGN_BELOW|GP_ALIGN_RIGHT,
	        blue_pixel, white_pixel, "Lorem Ipsum dolor sit...");

	/* Update the backend screen */
	GP_BackendFlip(backend);
}
Пример #4
0
static void redraw(GP_Backend *self)
{
	GP_Context *context = self->context;
	GP_Pixel white_pixel, black_pixel;

	black_pixel = GP_RGBToContextPixel(0x00, 0x00, 0x00, context);
	white_pixel = GP_RGBToContextPixel(0xff, 0xff, 0xff, context);

	GP_Fill(context, black_pixel);
	GP_Line(context, 0, 0, context->w - 1, context->h - 1, white_pixel);
	GP_Line(context, 0, context->h - 1, context->w - 1, 0, white_pixel);

	/* Update the backend screen */
	GP_BackendFlip(self);
}
Пример #5
0
void redraw_screen(void)
{
	GP_Fill(win, gray_pixel);

	GP_TextStyle style = GP_DEFAULT_TEXT_STYLE;

	switch (font_flag) {
	case 0:
		style.font = &GP_DefaultConsoleFont;
	break;
	case 1:
		style.font = &GP_DefaultProportionalFont;
	break;
	case 2:
		style.font = GP_FontTinyMono;
	break;
	case 3:
		style.font = GP_FontTiny;
	break;
	case 4:
		style.font = GP_FontC64;
	break;
	case 5:
		style.font = font;
	break;
	}

	style.pixel_xmul = mul;
	style.pixel_ymul = mul;
	style.pixel_xspace = space;
	style.pixel_yspace = space;
	style.char_xspace = tracking;

	/* Text alignment (we are always drawing to the right
	 * and below the starting point).
	 */
	int align = GP_ALIGN_RIGHT|GP_VALIGN_BELOW;

	struct FileLine *line = first_line;
	unsigned int i;
	for (i = 0; i < win->h/GP_TextHeight(&style); i++) {
		if (line == NULL)
			break;
		GP_Text(win, &style, 16, 16 + (1.0 * GP_TextHeight(&style))*i,
		        align, black_pixel, gray_pixel, line->text);
		line = line->next;
	}
}
Пример #6
0
int main(int argc, char *argv[])
{
	const char *backend_opts = "X11";
	int opt;

	while ((opt = getopt(argc, argv, "b:h")) != -1) {
		switch (opt) {
		case 'b':
			backend_opts = optarg;
		break;
		case 'h':
			GP_BackendInit(NULL, NULL, stderr);
			return 0;
		break;
		default:
			fprintf(stderr, "Invalid paramter '%c'\n", opt);
			return 1;
		}
	}

	backend = GP_BackendInit(backend_opts, "Input Test", stderr);

	if (backend == NULL) {
		fprintf(stderr, "Failed to initalize backend '%s'\n",
		        backend_opts);
		return 1;
	}

	win = backend->context;

	red   = GP_ColorToContextPixel(GP_COL_RED, win);
	green = GP_ColorToContextPixel(GP_COL_GREEN, win);
	white = GP_ColorToContextPixel(GP_COL_WHITE, win);
	black = GP_ColorToContextPixel(GP_COL_BLACK, win);

	GP_Fill(win, black);
	GP_BackendFlip(backend);

	for (;;) {
		GP_BackendWait(backend);
		event_loop();
	}
}
Пример #7
0
void redraw_screen(void)
{
	GP_Fill(win->context, black_pixel);

	/* draw axes intersecting in the middle, where text should be shown */
	GP_HLine(win->context, 0, X, Y/2, darkgray_pixel);
	GP_VLine(win->context, X/2, 0, Y, darkgray_pixel);

	switch (font_flag) {
	case 0:
		style.font = &GP_DefaultProportionalFont;
	break;
	case 1:
		style.font = &GP_DefaultConsoleFont;
	break;
	case 2:
		style.font = GP_FontTinyMono;
	break;
	case 3:
		style.font = GP_FontTiny;
	break;
	case 4:
		style.font = GP_FontC64;
	break;
	case 5:
		style.font = font;
	break;
	}

	GP_Text(win->context, &style, X/2, Y/2, GP_ALIGN_LEFT|GP_VALIGN_BELOW,
	        yellow_pixel, black_pixel, "bottom left");
	GP_Text(win->context, &style, X/2, Y/2, GP_ALIGN_RIGHT|GP_VALIGN_BELOW,
	        red_pixel, black_pixel, "bottom right");
	GP_Text(win->context, &style, X/2, Y/2, GP_ALIGN_RIGHT|GP_VALIGN_ABOVE,
	        blue_pixel, black_pixel, "top right");
	GP_Text(win->context, &style, X/2, Y/2, GP_ALIGN_LEFT|GP_VALIGN_ABOVE,
	        green_pixel, black_pixel, "top left");

	GP_HLine(win->context, 0, X, Y/3, darkgray_pixel);
	GP_Text(win->context, &style, X/2, Y/3, GP_ALIGN_CENTER|GP_VALIGN_BASELINE,
	        white_pixel, black_pixel, "x center y baseline");
}
Пример #8
0
static int redraw_help(GP_Backend *backend, unsigned int loff, GP_Coord xoff)
{
	GP_Context *c = backend->context;
	GP_Pixel black = GP_ColorToContextPixel(GP_COL_BLACK, c);
	GP_Pixel white = GP_ColorToContextPixel(GP_COL_WHITE, c);
	int i;

	GP_Fill(c, black);

	for (i = loff; i < keys_help_len; i++) {
		GP_Coord h = 2 + (i - loff) * 15;

		if (h + 2 >= (GP_Coord)c->h)
			goto out;

		GP_Print(c, NULL, 20 + 10 * xoff, h, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
		         white, black, "%s", keys_help[i]);
	}

out:
	GP_BackendFlip(backend);
	return i;
}
Пример #9
0
int main(int argc, char *argv[])
{
	const char *backend_opts = "X11";
	int opt;
	int pause_flag = 0;

	while ((opt = getopt(argc, argv, "b:Ii:Ps:r:")) != -1) {
		switch (opt) {
		case 'b':
			backend_opts = optarg;
		break;
		default:
			fprintf(stderr, "Invalid paramter '%c'\n", opt);
		}
	}

//	GP_SetDebugLevel(10);

	signal(SIGINT, sighandler);
	signal(SIGSEGV, sighandler);
	signal(SIGBUS, sighandler);
	signal(SIGABRT, sighandler);

	init_backend(backend_opts);

	context = backend->context;

	black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, context);
	white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, context);

	GP_Fill(context, black_pixel);
	GP_BackendFlip(backend);

	struct space *space;
	space = space_create(160, 10<<8, 10<<8, (context->w - 10)<<8, (context->h - 10)<<8);

	for (;;) {
		if (backend->Poll)
			GP_BackendPoll(backend);

		usleep(1000);

		/* Read and parse events */
		GP_Event ev;

		while (GP_BackendGetEvent(backend, &ev)) {

			GP_EventDump(&ev);

			switch (ev.type) {
			case GP_EV_KEY:
				if (ev.code != GP_EV_KEY_DOWN)
					continue;

				switch (ev.val.key.key) {
				case GP_KEY_ESC:
				case GP_KEY_ENTER:
				case GP_KEY_Q:
					GP_BackendExit(backend);
					return 0;
				break;
				case GP_KEY_P:
					pause_flag = !pause_flag;
				break;
				case GP_KEY_G:
					space->gay = 1;
				break;
				case GP_KEY_T:
					space->gay = 0;
				break;
				}
			break;
			}
		}

		if (!pause_flag) {
			space_time_tick(space, 1);
			space_draw_particles(context, space);
			GP_BackendFlip(backend);
		}
	}

	GP_BackendExit(backend);

	return 0;
}
Пример #10
0
void redraw_screen(void)
{
	GP_Fill(win->context, black_pixel);

	GP_TextStyle style = GP_DEFAULT_TEXT_STYLE;

	switch (font_flag) {
	case 0:
		style.font = &GP_DefaultProportionalFont;
	break;
	case 1:
		style.font = &GP_DefaultConsoleFont;
	break;
	case 2:
		style.font = GP_FontTiny;
	break;
	case 3:
		style.font = GP_FontTinyMono;
	break;
	case 4:
		style.font = font;
	break;
	}

	print_font_properties(style.font);

	/* Text alignment (we are always drawing to the right
	 * and below the starting point).
	 */
	int align = GP_ALIGN_RIGHT|GP_VALIGN_BELOW;

	const size_t TEST_STRING_COUNT = sizeof(test_strings)/sizeof(const char *);
	size_t i;
	for (i = 0; i < TEST_STRING_COUNT; i++) {
		const char *test_string = test_strings[i];

		style.pixel_xmul = 1;
		style.pixel_ymul = 1;
		style.pixel_xspace = 0;
		style.pixel_yspace = 0;
		style.char_xspace = tracking;

		GP_FillRectXYWH(win->context,
			16, SPACING*i + 16,
			GP_TextWidth(&style, test_string),
			GP_FontHeight(style.font),
			dark_gray_pixel);

		GP_RectXYWH(win->context,
			15, SPACING*i + 15,
			GP_TextMaxWidth(&style, strlen(test_string)) + 1,
			GP_FontHeight(style.font) + 1,
			blue_pixel);

		GP_Text(win->context, &style, 16, SPACING*i + 16, align,
		        white_pixel, dark_gray_pixel, test_string);

		style.pixel_xmul = 2;
		style.pixel_ymul = 2;
		style.pixel_yspace = 1;

		GP_Text(win->context, &style, 34, SPACING * i + 44, align,
		        white_pixel, black_pixel, test_string);

		GP_RectXYWH(win->context, 33, SPACING * i + 43,
		            GP_TextWidth(&style, test_string) + 1,
			    GP_TextHeight(&style) + 1, dark_gray_pixel);

		style.pixel_xmul = 4;
		style.pixel_ymul = 2;

		style.pixel_xspace = 1;
		style.pixel_yspace = 1;

		if (font_flag == 2 || font_flag == 3) {
			style.pixel_xmul = 2;
			style.pixel_ymul = 5;

			style.pixel_xspace = 2;
			style.pixel_yspace = 2;
		}

		GP_Text(win->context, &style, 64, SPACING*i + 88, align,
		        dark_gray_pixel, black_pixel, test_string);
	}
}
Пример #11
0
void clear_screen(void)
{
	GP_Fill(win->context, black);
	GP_BackendFlip(win);
}
Пример #12
0
int GP_ReadGIFEx(GP_IO *io, GP_Context **img,
                 GP_DataStorage *storage, GP_ProgressCallback *callback)
{
	GifFileType *gf;
	GifRecordType rec_type;
	GP_Context *res = NULL;
	GP_Pixel bg;
	int32_t x, y;
	int err;

	errno = 0;
#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
	gf = DGifOpen(io, gif_input_func, NULL);
#else
	gf = DGifOpen(io, gif_input_func);
#endif

	if (gf == NULL) {
		/*
		 * The giflib uses open() so when we got a failure and errno
		 * is set => open() has failed.
		 *
		 * When errno is not set the file content was not valid so we
		 * set errno to EIO.
		 */
		if (errno == 0)
			errno = EIO;

		return 1;
	}

	GP_DEBUG(1, "Have GIF image %ix%i, %i colors, %i bpp",
	         gf->SWidth, gf->SHeight, gf->SColorResolution,
		 gf->SColorMap ? gf->SColorMap->BitsPerPixel : -1);

	do {
		if (DGifGetRecordType(gf, &rec_type) != GIF_OK) {
			//TODO: error handling
			GP_DEBUG(1, "DGifGetRecordType() error %s (%i)",
			         gif_err_name(gif_err(gf)), gif_err(gf));
			err = EIO;
			goto err1;
		}

		GP_DEBUG(2, "Have GIF record type %s",
		         rec_type_name(rec_type));

		switch (rec_type) {
		case EXTENSION_RECORD_TYPE:
			if ((err = read_extensions(gf)))
				goto err1;
			continue;
		case IMAGE_DESC_RECORD_TYPE:
		break;
		default:
			continue;
		}

		if (DGifGetImageDesc(gf) != GIF_OK) {
			//TODO: error handling
			GP_DEBUG(1, "DGifGetImageDesc() error %s (%i)",
			         gif_err_name(gif_err(gf)), gif_err(gf)); 
			err = EIO;
			goto err1;
		}

		if (storage)
			fill_metadata(gf, storage);

		GP_DEBUG(1, "Have GIF Image left-top %ix%i, width-height %ix%i,"
		         " interlace %i, bpp %i", gf->Image.Left, gf->Image.Top,
			 gf->Image.Width, gf->Image.Height, gf->Image.Interlace,
			 gf->Image.ColorMap ? gf->Image.ColorMap->BitsPerPixel : -1);

		if (!img)
			break;

		res = GP_ContextAlloc(gf->SWidth, gf->SHeight, GP_PIXEL_RGB888);

		if (res == NULL) {
			err = ENOMEM;
			goto err1;
		}

		/* If background color is defined, use it */
		if (get_bg_color(gf, &bg)) {
			GP_DEBUG(1, "Filling bg color %x", bg);
			GP_Fill(res, bg);
		}

		/* Now finally read gif image data */
		for (y = gf->Image.Top; y < gf->Image.Height; y++) {
			uint8_t line[gf->Image.Width];

			DGifGetLine(gf, line, gf->Image.Width);

			unsigned int real_y = y;

			if (gf->Image.Interlace == 64) {
				real_y = interlace_real_y(gf, y);
				GP_DEBUG(3, "Interlace y -> real_y %u %u", y, real_y);
			}

			//TODO: just now we have only 8BPP
			for (x = 0; x < gf->Image.Width; x++)
				GP_PutPixel_Raw_24BPP(res, x + gf->Image.Left, real_y, get_color(gf, line[x]));

			if (GP_ProgressCallbackReport(callback, y - gf->Image.Top,
			                              gf->Image.Height,
						      gf->Image.Width)) {
				GP_DEBUG(1, "Operation aborted");
				err = ECANCELED;
				goto err2;
			}
		}

		//TODO: now we exit after reading first image
		break;

	} while (rec_type != TERMINATE_RECORD_TYPE);

	DGifCloseFile(gf);

	/* No Image record found :( */
	if (img && !res) {
		errno = EINVAL;
		return 1;
	}

	if (img)
		*img = res;

	return 0;
err2:
	GP_ContextFree(res);
err1:
	DGifCloseFile(gf);
	errno = err;
	return 1;
}