⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ogreglxconfig.cpp

📁 赫赫大名的 OGRE 游戏引擎
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	Widget mb1 = XtVaCreateManagedWidget("Menu", menuButtonWidgetClass, box, XtNlabel,curRenderName, 
		XtNresize, false,
		XtNresizable, false,
		XtNwidth, col2w, 	// Fixed width
		XtNheight, 18,
		XtNleft, XawChainLeft,
		XtNtop, XawChainTop,
		XtNright, XawChainLeft,
		XtNbottom, XawChainTop,
		XtNhorizDistance, col2x,
		XtNvertDistance, cury,
		NULL);

	Widget menu = XtVaCreatePopupShell("menu", simpleMenuWidgetClass, mb1, 
		0, NULL);

	RenderSystemList* renderers = Root::getSingleton().getAvailableRenderers();
	for (RenderSystemList::iterator pRend = renderers->begin();
	                pRend != renderers->end(); pRend++) {
		// Create callback data
		mRendererCallbackData.push_back(RendererCallbackData(this, *pRend, mb1));

		Widget entry = XtVaCreateManagedWidget("menuentry", smeBSBObjectClass, menu,
			XtNlabel, (*pRend)->getName().c_str(),
			0, NULL);
		XtAddCallback(entry, XtNcallback, (XtCallbackProc)&GLXConfigurator::renderSystemHandler, &mRendererCallbackData.back());
	}

	Widget bottomPanel = XtVaCreateManagedWidget("bottomPanel", formWidgetClass, box, 
		XtNsensitive, True, 
		XtNborderWidth, 0, 
		XtNwidth, 150, 	// Fixed width
		XtNleft, XawChainLeft,
		XtNtop, XawChainTop,
		XtNright, XawChainLeft,
		XtNbottom, XawChainTop,
		XtNhorizDistance, mWidth - 160,
		XtNvertDistance, mHeight - 40,
		NULL); 

	Widget helloButton = XtVaCreateManagedWidget("cancelButton", commandWidgetClass, bottomPanel, XtNlabel," Cancel ", NULL); 
	XtAddCallback(helloButton, XtNcallback, (XtCallbackProc)&GLXConfigurator::cancelHandler, this); 

	Widget exitButton = XtVaCreateManagedWidget("acceptButton", commandWidgetClass, bottomPanel, XtNlabel," Accept ", XtNfromHoriz,helloButton, NULL);
 	XtAddCallback(exitButton, XtNcallback, (XtCallbackProc)&GLXConfigurator::acceptHandler, this); 

	XtRealizeWidget(toplevel); 

	if(mRenderer)
		/* There was already a renderer selected; display its options */
		SetRenderer(mRenderer);

	return true;
}

Pixmap GLXConfigurator::CreateBackdrop(Window rootWindow, int depth) {
	int bpl;
	/* Find out number of bytes per pixel */
	switch(depth) {
	default:
		LogManager::getSingleton().logMessage("GLX backdrop: Undsupported bit depth");
		/* Unsupported bit depth */
		return 0;
	case 15:
	case 16:
		bpl = 2; break;
	case 24:
	case 32:
		bpl = 4; break;
	}
	/* Create background pixmap */
	unsigned char *data = 0; // Must be allocated with malloc

	try {
		Image img;
		/* Load backdrop image using OGRE */
		img.load(backdrop);
		if(img.getWidth() != mWidth || img.getHeight() != mHeight ||
			img.getFormat() != PF_R8G8B8) {
			// Invalid image format or size
			LogManager::getSingleton().logMessage("GLX backdrop: Invalid image "+backdrop+", format must be R8G8B8");
			return 0;
		}
		// Convert and copy image
		unsigned char *imgdata = (unsigned char*)img.getData();
		

		data = (unsigned char*)malloc(mWidth * mHeight * bpl); // Must be allocated with malloc
		int sptr = 0, dptr = 0;

		switch(depth) {
		case 16:
			for(int y=0; y<mHeight; y++) {
				for(int x=0; x<mWidth; x++) {
					// 5/6/5
					data[dptr + 0] = (imgdata[sptr + 0] & 0xF8) |
							 (imgdata[sptr + 1] >> 5);
					data[dptr + 1] = ((imgdata[sptr + 1] << 3) & 0xE0) | 
							 (imgdata[sptr + 2] >> 3);
					sptr += 3; dptr += 2;
				}
			}
			break;
		case 24:
		case 32:
			for(int y=0; y<mHeight; y++) {
				for(int x=0; x<mWidth; x++) {
					data[dptr + 0] = 0;
					data[dptr + 1] = imgdata[sptr + 0];
					data[dptr + 2] = imgdata[sptr + 1];
					data[dptr + 3] = imgdata[sptr + 2];
				
					sptr += 3;dptr += 4;
				}
			}
			break;
		}
	} catch(Exception &e) {
		// Could not find image; never mind
		LogManager::getSingleton().logMessage("GLX backdrop image not found: Warning");
		return 0;
	}
	
	GC context = XCreateGC (mDisplay, rootWindow, 0, NULL);

	/* put my pixmap data into the client side X image data structure */
	XImage *image = XCreateImage (mDisplay, NULL, depth, ZPixmap, 0, 
		(char*)data,
		mWidth, mHeight, 8,
		mWidth*bpl);
	image->byte_order = MSBFirst;

	/* tell server to start managing my pixmap */
	Pixmap rv = XCreatePixmap(mDisplay, rootWindow, mWidth,
		mHeight, depth);

	/* copy from client to server */
	XPutImage(mDisplay, rv, context, image, 0, 0, 0, 0,
	 	mWidth, mHeight);

	/* free up the client side pixmap data area */
	XDestroyImage(image); // also cleans data
	XFreeGC(mDisplay, context);

	return rv;
}
bool GLXConfigurator::Init() {
	// Init misc resources
	return true;
}
void GLXConfigurator::Draw() {
}
void GLXConfigurator::Main() {
	XtAppMainLoop(appContext);
}
void GLXConfigurator::Exit() {
	XtAppSetExitFlag(appContext);
}

void GLXConfigurator::SetRenderer(RenderSystem *r) {
	mRenderer = r;

	// Destroy each widget of GUI of previously selected renderer
	for(std::list<Widget>::iterator i=mRenderOptionWidgets.begin(); i!=mRenderOptionWidgets.end(); i++)
		XtDestroyWidget(*i);
	mRenderOptionWidgets.clear();
	mConfigCallbackData.back();

	// Create option GUI
	int cury = ystart + 1*rowh + 10;

	ConfigOptionMap options = mRenderer->getConfigOptions();
	// Process each option and create an optionmenu widget for it
	for (ConfigOptionMap::iterator it = options.begin();
					it != options.end(); it++) {
		Widget lb1 = XtVaCreateManagedWidget("topLabel", labelWidgetClass, box, XtNlabel, it->second.name.c_str(), XtNborderWidth, 0, 
			XtNwidth, col1w, 	// Fixed width
			XtNheight, 18,
			XtNleft, XawChainLeft,
			XtNtop, XawChainTop,
			XtNright, XawChainLeft,
			XtNbottom, XawChainTop,
			XtNhorizDistance, col1x,
			XtNvertDistance, cury,
			XtNjustify, XtJustifyLeft,
			NULL);
		mRenderOptionWidgets.push_back(lb1);
		Widget mb1 = XtVaCreateManagedWidget("Menu", menuButtonWidgetClass, box, XtNlabel, it->second.currentValue.c_str(), 
			XtNresize, false,
			XtNresizable, false,
			XtNwidth, col2w, 	// Fixed width
			XtNheight, 18,
			XtNleft, XawChainLeft,
			XtNtop, XawChainTop,
			XtNright, XawChainLeft,
			XtNbottom, XawChainTop,
			XtNhorizDistance, col2x,
			XtNvertDistance, cury,
			NULL);
		mRenderOptionWidgets.push_back(mb1);

		Widget menu = XtVaCreatePopupShell("menu", simpleMenuWidgetClass, mb1, 
			0, NULL);

		// Process each choice
		StringVector::iterator opt_it;
		for (opt_it = it->second.possibleValues.begin();
		                opt_it != it->second.possibleValues.end(); opt_it++) {
			// Create callback data
			mConfigCallbackData.push_back(ConfigCallbackData(this, it->second.name, *opt_it, mb1));

			Widget entry = XtVaCreateManagedWidget("menuentry", smeBSBObjectClass, menu,
				XtNlabel, (*opt_it).c_str(),
				0, NULL);
			XtAddCallback(entry, XtNcallback, (XtCallbackProc)&GLXConfigurator::configOptionHandler, &mConfigCallbackData.back());
		}
		cury += rowh;
	}
}

void GLXConfigurator::SetConfigOption(const std::string &optionName, const std::string &valueName) {
	if(!mRenderer)
		// No renderer set -- how can this be called?
		return;
	mRenderer->setConfigOption(optionName, valueName);
}

bool GLXConfig::display(void) {
	GLXConfigurator test;
	/* Should this be called here? */
	Root::getSingleton().restoreConfig();
	/* Select previously selected rendersystem */
	if(Root::getSingleton().getRenderSystem())
		test.SetRenderSystem(Root::getSingleton().getRenderSystem());
	/* Attempt to create the window */
	if(!test.CreateWindow()) {
		Except(Exception::ERR_INTERNAL_ERROR,
		       "Could not create configuration dialog",
		       "GLXConfig::display");
	}
	/* Modal loop */
	test.Main();
	if(!test.accept) {
		/* User did not accept */
		return false;
	}

	/* All done */
	Root::getSingleton().setRenderSystem(test.mRenderer);
	Root::getSingleton().saveConfig();

	return true;
}

};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -