OHP3D.cpp
branchv_0
changeset 34 7ea796b00538
parent 33 4620bba4fa40
child 38 808f05faab30
equal deleted inserted replaced
33:4620bba4fa40 34:7ea796b00538
   196 	void updateVariableLocations();
   196 	void updateVariableLocations();
   197 	bool reloadShader(const std::string& fileName);
   197 	bool reloadShader(const std::string& fileName);
   198 	void setTitle(const std::string& suffix = "");
   198 	void setTitle(const std::string& suffix = "");
   199 	static const std::string getDefaultFile(const std::string& relativePath);
   199 	static const std::string getDefaultFile(const std::string& relativePath);
   200 
   200 
       
   201 	void goPage(int count);
       
   202 	void goHome();
       
   203 	void goEnd();
       
   204 	void goPageMouse(XButtonEvent ev);
   201 };
   205 };
   202 
   206 
   203 OHP3D::OHP3D(const Configuration& configuration) :
   207 OHP3D::OHP3D(const Configuration& configuration) :
   204 impl(new Impl(configuration)) {
   208 impl(new Impl(configuration)) {
   205 }
   209 }
   306 	}
   310 	}
   307 
   311 
   308 	// rended the 3D scene even before the first event:
   312 	// rended the 3D scene even before the first event:
   309 	runShaders();
   313 	runShaders();
   310 	glXSwapBuffers(dpy, win);
   314 	glXSwapBuffers(dpy, win);
   311 
       
   312 	auto goPage = [&](int count) {
       
   313 		// TODO: support pages with different ratios
       
   314 		ctx.moveRight(count * 1.8 * textures[0]->getRatio());
       
   315 	};
       
   316 
       
   317 	auto goHome = [&]() {
       
   318 		ctx.cameraFront = initialCtx.cameraFront;
       
   319 		ctx.cameraPos = initialCtx.cameraPos;
       
   320 		ctx.cameraUp = initialCtx.cameraUp;
       
   321 	};
       
   322 
       
   323 	auto goEnd = [&]() {
       
   324 		goHome();
       
   325 		goPage(textures.size() - 1);
       
   326 	};
       
   327 
       
   328 	auto goPageMouse = [&](XButtonEvent ev) {
       
   329 		XWindowAttributes gwa;
       
   330 		XGetWindowAttributes(dpy, win, &gwa);
       
   331 
       
   332 		bool top = ev.y < gwa.height / 2, bottom = !top;
       
   333 		bool left = ev.x < gwa.width / 2, right = !left;
       
   334 
       
   335 		if (top && left) goHome();
       
   336 		else if (top && right) goEnd();
       
   337 		else if (bottom && left) goPage(-1);
       
   338 		else if (bottom && right) goPage(+1);
       
   339 	};
       
   340 
       
   341 
   315 
   342 	for (XEvent xev; keepRunningX11;) {
   316 	for (XEvent xev; keepRunningX11;) {
   343 		int epollEventCount = epoll.wait();
   317 		int epollEventCount = epoll.wait();
   344 		//std::cout << "trace: epoll.wait() = " << epollEventCount << std::endl;
   318 		//std::cout << "trace: epoll.wait() = " << epollEventCount << std::endl;
   345 		for (int epollEvent = 0; epollEvent < epollEventCount; epollEvent++) {
   319 		for (int epollEvent = 0; epollEvent < epollEventCount; epollEvent++) {
   726 			return true;
   700 			return true;
   727 		}
   701 		}
   728 	}
   702 	}
   729 	return false;
   703 	return false;
   730 }
   704 }
       
   705 
       
   706 void OHP3D::Impl::goPage(int count) {
       
   707 	// TODO: support pages with different ratios
       
   708 	ctx.moveRight(count * 1.8 * textures[0]->getRatio());
       
   709 }
       
   710 
       
   711 void OHP3D::Impl::goHome() {
       
   712 	ctx.cameraFront = initialCtx.cameraFront;
       
   713 	ctx.cameraPos = initialCtx.cameraPos;
       
   714 	ctx.cameraUp = initialCtx.cameraUp;
       
   715 }
       
   716 
       
   717 void OHP3D::Impl::goEnd() {
       
   718 	goHome();
       
   719 	goPage(textures.size() - 1);
       
   720 }
       
   721 
       
   722 void OHP3D::Impl::goPageMouse(XButtonEvent ev) {
       
   723 	XWindowAttributes gwa;
       
   724 	XGetWindowAttributes(dpy, win, &gwa);
       
   725 
       
   726 	bool top = ev.y < gwa.height / 2, bottom = !top;
       
   727 	bool left = ev.x < gwa.width / 2, right = !left;
       
   728 
       
   729 	if (top && left) goHome();
       
   730 	else if (top && right) goEnd();
       
   731 	else if (bottom && left) goPage(-1);
       
   732 	else if (bottom && right) goPage(+1);
       
   733 }