public void AddNewProduct(ProductModel model, float x, float y, float width, float height, bool realDimensions, int angle) { float viewWidth = view.Get(ProductGrid.PropertyEnum.Panel).Width, viewHeight = view.Get(ProductGrid.PropertyEnum.Panel).Height, newX = realDimensions ? x : x / viewWidth * meterWidth, newY = realDimensions ? y : y / viewHeight * meterHeight; PointF center = (realDimensions) ? new PointF(x, y) : new PointF(newX - width / 2, newY - height / 2); int currentangle = angle; SizeF size = new SizeF(width, height); model.Size = size; PlacedProduct newProduct = new PlacedProduct(model, center, currentangle); // Do not add product to field if it has collision if (!collisionHandler.Collision(newProduct, placedProducts)) { placedProducts.Add(newProduct); ((ProductGrid)view).productList.fixInformation(); } }
public void MoveProduct(ICollisionHandler <PlacedProduct> handler, PlacedProduct selectedProduct, List <PlacedProduct> placedProducts, int boundWidth, int boundHeight, float realWidth, float realHeight, float x, float y, bool real) { float selectedWidth = selectedProduct.Product.Size.Width, selectedHeight = selectedProduct.Product.Size.Height; float newX = (real) ? x : x / (float)boundWidth * realWidth - selectedWidth / 2, newY = (real) ? y : y / (float)boundHeight * realHeight - selectedHeight / 2; if (newX <= 0) { newX = 0; } if (newX + selectedWidth / 2 >= realWidth - selectedWidth / 2) { newX = realWidth - selectedWidth; } if (newY <= 0) { newY = 0; } if (newY + selectedHeight / 2 >= realHeight - selectedHeight / 2) { newY = realHeight - selectedHeight; } PointF newLocation = new PointF(newX, newY); selectedProduct.Location = !handler.Collision(selectedProduct, placedProducts) ? newLocation : selectedProduct.OriginalLocation; }
public void MoveProduct(ICollisionHandler<PlacedProduct> handler, PlacedProduct selectedProduct, List<PlacedProduct> placedProducts, int boundWidth, int boundHeight, float realWidth, float realHeight, float x, float y, bool real) { float selectedWidth = selectedProduct.Product.Size.Width, selectedHeight = selectedProduct.Product.Size.Height; float newX = (real) ? x : x/(float) boundWidth*realWidth - selectedWidth/2, newY = (real) ? y : y/(float) boundHeight*realHeight - selectedHeight/2; if (newX <= 0) newX = 0; if (newX + selectedWidth/2 >= realWidth - selectedWidth/2) newX = realWidth - selectedWidth; if (newY <= 0) newY = 0; if (newY + selectedHeight/2 >= realHeight - selectedHeight/2) newY = realHeight - selectedHeight; PointF newLocation = new PointF(newX, newY); selectedProduct.Location = !handler.Collision(selectedProduct, placedProducts) ? newLocation : selectedProduct.OriginalLocation; }