Example #1
0
int main(void)
{
	const char *backend_opts = "X11";

	win = GP_BackendInit(backend_opts, "Random Shape Test", stderr);

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

	white = GP_ColorToContextPixel(GP_COL_WHITE, win->context);
	black = GP_ColorToContextPixel(GP_COL_BLACK, win->context);

	for (;;) {
		GP_BackendPoll(win);
		event_loop();

		usleep(20000);

		if (pause_flag)
			continue;

		redraw_screen();
		GP_BackendFlip(win);
	}
}
Example #2
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;
}
Example #3
0
int main(int argc, char *argv[])
{
	GP_Backend *backend;
	const char *backend_opts = "X11:350x350";
	int opt;
	GP_PixelType emul_type = GP_PIXEL_UNKNOWN;

	while ((opt = getopt(argc, argv, "b:h:p:")) != -1) {
		switch (opt) {
		case 'b':
			backend_opts = optarg;
		break;
		case 'p':
			emul_type = GP_PixelTypeByName(optarg);

			if (emul_type == GP_PIXEL_UNKNOWN) {
				fprintf(stderr, "Invalid pixel type '%s'\n", optarg);
				return 1;
                        }
		break;
		case 'h':
			GP_BackendInit("help", NULL);
			return 0;
		break;
		default:
			fprintf(stderr, "Invalid paramter '%c'\n", opt);
			return 1;
		}
	}

	/* Turn on debug messages */
	GP_SetDebugLevel(10);

	backend = GP_BackendInit(backend_opts, "Virtual Backend Example");

	if (emul_type != GP_PIXEL_UNKNOWN) {
		GP_Backend *emul;

		/*
		 * Create an emulated backend on the top of real backend.
		 *
		 * The GP_BACKEND_CALL_EXIT says that when calling exit on
		 * emulated backend, the real backend exit will be called as
		 * well.
		 */
		emul = GP_BackendVirtualInit(backend, emul_type, GP_BACKEND_CALL_EXIT);

		if (emul == NULL) {
			fprintf(stderr, "Failed to create Virtual Backend\n");
			GP_BackendExit(backend);
			return 1;
		}

		/* Once created virtual backend behaves exactly like a real one */
		backend = emul;
	}

	redraw(backend);

	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:
				switch (ev.val.key.key) {
				case GP_KEY_ESC:
				case GP_KEY_Q:
					GP_BackendExit(backend);
					return 0;
				break;
				}
			break;
			case GP_EV_SYS:
				switch(ev.code) {
				case GP_EV_SYS_RESIZE:
					GP_BackendResizeAck(backend);
					redraw(backend);
				break;
				}
			break;
			}
		}
	}

	GP_BackendExit(backend);

	return 0;
}