当前位置: 首页>>代码示例>>C++>>正文


C++ Controller::dragAnchorPoint方法代码示例

本文整理汇总了C++中Controller::dragAnchorPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ Controller::dragAnchorPoint方法的具体用法?C++ Controller::dragAnchorPoint怎么用?C++ Controller::dragAnchorPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Controller的用法示例。


在下文中一共展示了Controller::dragAnchorPoint方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: MouseButtonCallback

// this function is being called when a mouse button is pressed
void GLFWCALL MouseButtonCallback(int button, int mouseEvent){
	int x,y;
	glfwGetMousePos(&x, &y);
	
	try{
		Controller* PolyFun = Controller::getInstance();
		
		// if mouse was clicked on canvas
		if(PolyFun->getCanvasSelection(x,y)){
			if(mouseEvent == GLFW_PRESS){
				switch(button){
					// if the pen tool is activated and the left button is pressed
					case GLFW_MOUSE_BUTTON_LEFT:
						if(PolyFun->getButton("penTool") != NULL && PolyFun->getButton("penTool")->activated() && PolyFun->getSelectedPolygon() != NULL){
							PolyFun->addAnchorPoint(x,y);
							PolyFun->updateWindow();
						};
						if(PolyFun->getButton("eraser") != NULL && PolyFun->getButton("eraser")->activated()) PolyFun->deletePoint(x,y); // delete point if clicked on one while the eraser is active
						break;
					case GLFW_MOUSE_BUTTON_RIGHT:
						if(PolyFun->getButton("penTool") != NULL) PolyFun->getButton("penTool")->setActivation(false); // turn the drawing button off
						if(PolyFun->getButton("eraser") != NULL) PolyFun->getButton("eraser")->setActivation(false); // turn the eraser off
						PolyFun->dragAnchorPoint(x,y);
						break;
					default: ;
						break;
				}
				PolyFun->selectPolygon(x,y); // selects the polygon with the coordinated x and y
				if(PolyFun->getPolygon(x,y) == NULL){
					PolyFun->deselectAllPolygons(); // deselect all polygons if clicked on the paper and not on a polygon
					if(PolyFun->getButton("penTool") != NULL) PolyFun->getButton("penTool")->setActivation(false); // turn the drawing button off
				}
				PolyFun->updateWindow();
			} else if(mouseEvent == GLFW_RELEASE){
				switch(button){
					case GLFW_MOUSE_BUTTON_RIGHT: PolyFun->releaseDraggedAnchorPoint();
						break;
					case GLFW_MOUSE_BUTTON_LEFT: PolyFun->releaseSlider();
						break;
					default: ;
						break;
				}
			}
		// if clicked outside the canvas
		} else {
			Button* b = PolyFun->getButton(x,y);
			Slider* s = PolyFun->getSlider(x,y);
			if(mouseEvent == GLFW_PRESS){
				switch(button){
					case GLFW_MOUSE_BUTTON_LEFT:
						if(b != NULL){
							if(b->getName() == "penTool"){
								if(b->activated()){
									// deactivate the activated button by clicking on it again
									std::cout << b->getName() << " has been deactivated" << std::endl;
									b->setActivation(false);
									PolyFun->deselectAllPolygons(); // reset selection of all polygons
								} else {
									// activate the pen tool and deactivate the eraser
									if(PolyFun->getButton("eraser") != NULL) PolyFun->getButton("eraser")->setActivation(false);
									b->setActivation(true);
									std::cout << b->getName() << " has been activated" << std::endl;
									if(PolyFun->getSelectedPolygon() == NULL) PolyFun->newPolygon(PolyFun->colour.r, PolyFun->colour.g, PolyFun->colour.b, PolyFun->hardness, PolyFun->drawingMode, PolyFun->polygonWidth);
								};
							} else if(b->getName() == "eraser"){
								if(b->activated()){
									PolyFun->deselectAllPolygons(); // reset selection of all polygons
									// deactivate the activated button by clicking on it again
									b->setActivation(false);
									std::cout << b->getName() << " has been deactivated" << std::endl;
								} else {
									// activate the eraser and deactivate the pen tool
									if(PolyFun->getButton("penTool") != NULL) PolyFun->getButton("penTool")->setActivation(false);
									b->setActivation(true);
									std::cout << b->getName() << " has been activated" << std::endl;
								};
							} else if(b->getName() == "lineStrip"){
								std::cout << b->getName() << " has been activated" << std::endl;
								// deactivate other mode buttons
								if(PolyFun->getButton("lineLoop") != NULL) PolyFun->getButton("lineLoop")->setActivation(false);
								if(PolyFun->getButton("filledPolygon") != NULL) PolyFun->getButton("filledPolygon")->setActivation(false);
								b->setActivation(true);
								PolyFun->setDrawingMode(Polytope2D::LINE);
							} else if(b->getName() == "lineLoop"){
								std::cout << b->getName() << " has been activated" << std::endl;
								// deactivate other mode buttons
								if(PolyFun->getButton("lineStrip") != NULL) PolyFun->getButton("lineStrip")->setActivation(false);
								if(PolyFun->getButton("filledPolygon") != NULL) PolyFun->getButton("filledPolygon")->setActivation(false);
								b->setActivation(true);
								PolyFun->setDrawingMode(Polytope2D::LINELOOP);
							} else if(b->getName() == "filledPolygon"){
								std::cout << b->getName() << " has been activated" << std::endl;
								// deactivate other mode buttons
								if(PolyFun->getButton("lineStrip") != NULL) PolyFun->getButton("lineStrip")->setActivation(false);
								if(PolyFun->getButton("lineLoop") != NULL) PolyFun->getButton("lineLoop")->setActivation(false);
								b->setActivation(true);
								PolyFun->setDrawingMode(Polytope2D::POLYGON);
							} else if(b->getName() == "hardness"){
								std::cout << b->getName() << " has been activated" << std::endl;
//.........这里部分代码省略.........
开发者ID:noshaba,项目名称:PolyFun,代码行数:101,代码来源:Controller.cpp


注:本文中的Controller::dragAnchorPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。