コード例 #1
0
JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateCursor
  (JNIEnv *env, jclass clazz, jlong display, jint width, jint height, jint x_hotspot, jint y_hotspot, jint num_images, jobject image_buffer, jint images_offset, jobject delay_buffer, jint delays_offset)
{
	Display *disp = (Display *)(intptr_t)display;
	const int *delays = NULL;
	if (delay_buffer != NULL)
		delays = (const int *)(*env)->GetDirectBufferAddress(env, delay_buffer) + delays_offset;		
	XcursorPixel *pixels = (XcursorPixel *)(*env)->GetDirectBufferAddress(env, image_buffer) + images_offset;
	int stride = width*height;
	XcursorImages *cursor_images = XcursorImagesCreate(num_images);
	if (cursor_images == NULL) {
		throwException(env, "Could not allocate cursor.");
		return None;
	}
	cursor_images->nimage = num_images;
	int i;
	for (i = 0; i < num_images; i++) {
		XcursorImage *cursor_image = XcursorImageCreate(width, height);
		cursor_image->xhot = x_hotspot;
		cursor_image->yhot = y_hotspot;
		cursor_image->pixels = &(pixels[stride*i]);
		if (num_images > 1)
			cursor_image->delay = delays[i];		
		cursor_images->images[i] = cursor_image;
	}
	Cursor cursor = XcursorImagesLoadCursor(disp, cursor_images);
	XcursorImagesDestroy(cursor_images);
	return cursor;
}
コード例 #2
0
void CHwX11Cursor::Finish()
{
	if (cimages.size()<1)
		return;

	//resize images
	for (std::vector<XcursorImage*>::iterator it = cimages.begin(); it < cimages.end(); ++it)
		resizeImage(*it, xmaxsize, ymaxsize);

	XcursorImages *cis = XcursorImagesCreate(cimages.size());
	cis->nimage = cimages.size();
	for (int i = 0; i < int(cimages.size()); ++i) {
		XcursorImage* ci = cimages[i];
		ci->xhot = (hotSpot==CMouseCursor::TopLeft) ? 0 : ci->width/2;
		ci->yhot = (hotSpot==CMouseCursor::TopLeft) ? 0 : ci->height/2;
		cis->images[i] = ci;
	}

	SDL_SysWMinfo info;
	SDL_VERSION(&info.version);
	if (!SDL_GetWMInfo(&info)) {
		XcursorImagesDestroy(cis);
		cimages.clear();
		logOutput.Print("SDL error: can't get X11 window info");
		return;
	}

	cursor = XcursorImagesLoadCursor(info.info.x11.display,cis);
	XcursorImagesDestroy(cis);
	cimages.clear();
}