示例#1
0
void MapViewer::refocus_map() {
    //Get the object
    ObjectManager& object_manager = ObjectManager::get_instance();

    if (map_focus_object == 0) {
        LOG(INFO) << "MapViewer::refocus_map: No focus.";
        return;
    }

    std::shared_ptr<Sprite> sprite = object_manager.get_object<Sprite>(map_focus_object);

    // If such an sprite exists, move the map to it
    if (sprite) {
        set_display_x(centre_point_in_range(
            // half-tile offset to take centre of sprite
            /* point  */ float(sprite->get_position().x) + 0.5f,
            /* length */ float(map->get_width()),
            /* bound  */ get_display_width()
        ));

        set_display_y(centre_point_in_range(
            // half-tile offset to take centre of sprite
            /* point  */ float(sprite->get_position().y) + 0.5f,
            /* length */ float(map->get_height()),
            /* bound  */ get_display_height()
        ));
    } else {
        LOG(INFO) << "MapViewer::refocus_map: No sprites have focus.";
    }
    Engine::text_updater();
}
示例#2
0
void perspective_camera::calculate_view()
{
	// calculate subpixel pitch
	m_pixel_pitch = std::tanf((m_vertical_fov * degrees_to_radians) * 0.5) / (get_display_height() * 0.5);
	m_subpixel_pitch = (1.0 / m_sample_rate) * m_pixel_pitch;
	
	// first calculate the top and left edge
	m_origin_pixel.y = std::tanf((m_vertical_fov * degrees_to_radians) * 0.5);
	m_origin_pixel.x = -(m_origin_pixel.y * get_aspect_ratio());

	// advance the top left corner half the pixel pitch to the right and to the bottom
	// origin pixel is situated at the top left.  we can derive the other pixels by adding and multiplying by pixel pitch
	//m_origin_pixel.x += (m_pixel_pitch * 0.5);
	//m_origin_pixel.y -= (m_pixel_pitch * 0.5);
}
示例#3
0
int
get_optimal_height(int h)
{
	int height, dh;

	resize_inc = get_height_inc();
	/* readjust height to new resize_inc, +5 prevents the window
	 * from getting too small */
	height = (h / resize_inc) * resize_inc + 5;
	if (!height)
		height = resize_inc;
	dh = get_display_height() - (opt_y_orig + opt_bw);
	if (height > dh)
		height = (dh / resize_inc) * resize_inc + 5;
	return height;
}
示例#4
0
const ray& perspective_camera::generate_ray(ray& out, const unsigned int x, const unsigned int y, const unsigned int sx, const unsigned int sy)
{
	// maximum x is (get_display_width - 1)
	// maximum y is (get_display_height - 1)
	assert(x < get_display_width());
	assert(y < get_display_height());

	out.m_origin = get_eye();

	// calculate pixel coordinates by offsetting origin pixel
	point3 subpixel(m_origin_pixel.x + (m_pixel_pitch * x), m_origin_pixel.y - (m_pixel_pitch * y), -1.0);	// z = -1 because we are using the RH coordinate system
	subpixel.x = subpixel.x + ((m_subpixel_pitch * sx) + (m_subpixel_pitch * 0.5));
	subpixel.y = subpixel.y + ((m_subpixel_pitch * sy) + (m_subpixel_pitch * 0.5));

	out.m_direction = subpixel - out.m_origin;

	normalize(out.m_direction, out.m_direction);

	return out;
}
示例#5
0
int
main(int argc, char *argv[])
{
	KeySym key;
	XEvent event;
	int hidden = 1;
	int fullscreen = 0;
	int i, tmp;
	int old_height = 0;
	Window tmpwin, last_focused, current_focused;
	XWindowAttributes wa;

	/* strip the path from argv[0] if there is one */
	progname = strrchr(argv[0], '/');
	if (!progname)
		progname = argv[0];
	else
		progname++;

	for (i = 1; i < argc; i++) {
		if (!strcmp(argv[i], "-h")) {
			printf("%s:\n"
				   "-e: program to execute\n"
				   "you can configure me via xresources:\n"
				   "%s*foo:value\n"
				   "foo can be any standard xterm/urxvt/st xresource or:\n"
				   "resource               default value\n\n"
				   "term:                  xterm\n"
				   "restart:               0\n"
				   "xOffset:               0\n"
				   "yOffset:               0\n"
				   "xrandrSupport:         0\n"
				   "screenWidth:           Display width\n"
				   "consoleHeight:         10\n"
				   "aniDelay:              40\n"
				   "stepSize;              1\n"
				   "toggleKey:             ControlAlt+y\n"
				   "keySmaller:            Control+KP_Subtract\n"
				   "keyBigger:             Control+KP_Add\n" "keyFull:               Alt+F11\n", progname, progname);
			exit(0);
		}
	}

	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, " can not open dpy %s", XDisplayName(NULL));
	}
	screen = DefaultScreen(dpy);
	root = RootWindow(dpy, screen);
	XSetErrorHandler(handle_xerror);
	cursor = XCreateFontCursor(dpy, XC_double_arrow);
	get_defaults();
	init_win();
	init_command(argc, argv);
	init_xterm(1);
	while (1) {
		XNextEvent(dpy, &event);
		switch (event.type) {
		case FocusOut:
			/* Always keep input focus when visible */
			if (!hidden)
				XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
			break;
		case EnterNotify:
			XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
			XSync(dpy, False);
			break;
		case LeaveNotify:
			if (last_focused && event.xcrossing.detail != NotifyInferior) {
				XSetInputFocus(dpy, last_focused, RevertToPointerRoot, CurrentTime);
				XSync(dpy, False);
			}
			break;
		case KeyPress:
			key = XKeycodeToKeysym(dpy, event.xkey.keycode, 0);
			if (key == opt_key) {
				if (!hidden) {
					XGetInputFocus(dpy, &current_focused, &revert_to);
					if (last_focused && current_focused == termwin)
						XSetInputFocus(dpy, last_focused, RevertToPointerRoot, CurrentTime);
					/* else
					   XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); */
					if (opt_step && !fullscreen)
						roll(UP);
					XUnmapWindow(dpy, win);
					hidden = 1;
					XSync(dpy, False);
				}
				else {
					XGetInputFocus(dpy, &last_focused, &revert_to);
					last_focused = get_toplevel_parent(last_focused);

					if (opt_step && !fullscreen) {
						XGrabServer(dpy);
						roll(DOWN);
						XUngrabServer(dpy);
					}
					else if (opt_xrandr)
						update_geom(last_focused);
					XMoveWindow(dpy, win, opt_x, opt_y);
					XMapWindow(dpy, win);
					XRaiseWindow(dpy, win);
					XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
					hidden = 0;
					XSync(dpy, False);
					XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
					XSync(dpy, False);
				}
				break;
			}
			if (!hidden) {
				if (key == opt_key_full) {
					if (!fullscreen) {
						old_height = height;
						height = get_optimal_height(get_display_height());
						fullscreen = 1;
					}
					else {
						height = old_height;
						fullscreen = 0;
					}
				}

				/* update height inc just in case something changed for the
				 * terminal, i.e. font size */
				resize_inc = get_height_inc();
				if (key == opt_key_bigger)
					height += resize_inc;
				if (key == opt_key_smaller)
					height -= resize_inc;
				if (height < resize_inc)
					height = resize_inc;
				height = get_optimal_height(height);
				resize_term(opt_width, height);
				XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
				XSync(dpy, False);
			}
			break;
		case ButtonPress:
			resize();
			XSync(dpy, False);
			break;
		case UnmapNotify:
			if (event.xunmap.window == termwin) {
				if (opt_restart) {
					if (opt_restart_hidden) {
						roll(UP);
						hidden = 1;
					}
					init_xterm(0);
					XSync(dpy, False);
					if (opt_restart_hidden && last_focused)
						XSetInputFocus(dpy, last_focused, RevertToPointerRoot, CurrentTime);
					else
						XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
				}
				else {
					if (last_focused)
						XSetInputFocus(dpy, last_focused, RevertToPointerRoot, CurrentTime);
					XSync(dpy, False);
					exit(0);
				}
			}
			break;
		}
	}
	return 0;
}