protected void _drawResizeBox(Graphics gfx) { if (_windowSelected) { _windowBox = new resizeSelectBox(this, resizeSelectBox.boxTypes.resize, Color.White); _windowBox.draw(gfx); } else { _itemBox = new resizeSelectBox(new Rectangle(_itemLocation, _itemSize), resizeSelectBox.boxTypes.resize, Color.Blue); _itemBox.draw(gfx); //_drawSelectedBox(gfx); //this will draw the window ontop of the item box } }
public void resizeItem(resizeSelectBox.resizeDirection resizeDirection, float xPerc, float yPerc, Boolean keepAspect) { //this is only called when the groupingBox is resizing each element //so this only affects the windowSize float aspectRatio = _windowSize_units.Width / _windowSize_units.Height; int fixedX; int fixedY; int newX; int newY; switch (resizeDirection) { case resizeSelectBox.resizeDirection.sW: fixedX = Convert.ToInt16((float)this.location.X + (_windowSize_units.Width * _magnification)); _windowSize_units.Height = _windowSize_units.Height * yPerc; if (!keepAspect) _windowSize_units.Width = _windowSize_units.Width * xPerc; else _windowSize_units.Width = aspectRatio * _windowSize_units.Height; newX = fixedX - Convert.ToInt16(_windowSize_units.Width * _magnification); _windowLocation = new Point(newX, _windowLocation.Y); _windowLocationPMF_units.X = (float)newX / _magnification; break; case resizeSelectBox.resizeDirection.sE: _windowSize_units.Height = _windowSize_units.Height * yPerc; if (!keepAspect) _windowSize_units.Width = _windowSize_units.Width * xPerc; else _windowSize_units.Width = aspectRatio * _windowSize_units.Height; break; case resizeSelectBox.resizeDirection.nE: fixedY = Convert.ToInt16((float)this.location.Y + (_windowSize_units.Height * _magnification)); _windowSize_units.Height = _windowSize_units.Height * yPerc; if (!keepAspect) _windowSize_units.Width = _windowSize_units.Width * xPerc; else _windowSize_units.Width = aspectRatio * _windowSize_units.Height; newY = fixedY - Convert.ToInt16(_windowSize_units.Height * _magnification); _windowLocationPMF_units.Y = (float)newY / _magnification; _windowLocation = new Point(_windowLocation.X, newY); break; case resizeSelectBox.resizeDirection.nW: fixedX = Convert.ToInt16((float)this.location.X + (_windowSize_units.Width * _magnification)); fixedY = Convert.ToInt16((float)this.location.Y + (_windowSize_units.Height * _magnification)); _windowSize_units.Height = _windowSize_units.Height * yPerc; if (!keepAspect) _windowSize_units.Width = _windowSize_units.Width * xPerc; else _windowSize_units.Width = aspectRatio * _windowSize_units.Height; newX = fixedX - Convert.ToInt16(_windowSize_units.Width * _magnification); newY = fixedY - Convert.ToInt16(_windowSize_units.Height * _magnification); _windowLocation = new Point(newX, newY); _windowLocationPMF_units = new PointF((float)_windowLocation.X / _magnification, (float)_windowLocation.Y / _magnification); break; } _windowSize = new Size(Convert.ToInt16(_windowSize_units.Width * _magnification),Convert.ToInt16(_windowSize_units.Height * _magnification)); _windowAspectRatio = _windowSize_units.Width / _windowSize_units.Height; }
void _createGroupingBox() { List<placeableItem> selectedItems = _getSelectedItems(); int minX = 0; int minY = 0; int maxX = 0; int maxY = 0; int loopCounter = 0; foreach (placeableItem selectedItem in selectedItems) { if (loopCounter == 0) { minX = selectedItem.location.X; minY = selectedItem.location.Y; maxX = selectedItem.location.X + selectedItem.size.Width; maxY = selectedItem.location.Y + selectedItem.size.Height; } else { if (selectedItem.location.X < minX) minX = selectedItem.location.X; if (selectedItem.location.Y < minY) minY = selectedItem.location.Y; if ((selectedItem.location.X + selectedItem.size.Width) > (maxX)) maxX = selectedItem.location.X + selectedItem.size.Width; if ((selectedItem.location.Y + selectedItem.size.Height) > (maxY)) maxY = selectedItem.location.Y + selectedItem.size.Height; } //Console.WriteLine(String.Concat("Item #", loopCounter, " size - w:", selectedItem.size.Width, " h:", selectedItem.size.Height)); loopCounter++; } _groupingRectangle = new Rectangle(new Point(minX, minY), new Size(maxX - minX, maxY - minY)); //Console.WriteLine(String.Concat("GBLoc - (",_groupingRectangle.Location.X,",",_groupingRectangle.Location.Y,") : GBSize - w:",_groupingRectangle.Width," h:",_groupingRectangle.Height)); _GroupingBox = new resizeSelectBox(_groupingRectangle, resizeSelectBox.boxTypes.resize); }
protected void _drawSelectedBox(Graphics gfx) { _windowBox = new resizeSelectBox(this, resizeSelectBox.boxTypes.selected, Color.White); _windowBox.draw(gfx); }
void _layoutArea_MouseDown(object sender, MouseEventArgs e) { mouseDownPosition = e.Location; if ((_showGroupingBox) && (_GroupingBox.hover(e.Location))) { this.currentLayoutAction = layoutActions.groupResize; //_groupingBoxResize = true; _groupingBoxResizeDirection = _GroupingBox.direction; } placeableItem previousSelectedItem = null; if (!_showGroupingBox) { if (_selectedItem != null) previousSelectedItem = _selectedItem; } List<placeableItem> containingItems = new List<placeableItem>(); foreach (placeableItem placedItem in _pageMatFrame.placedItems) { if (placedItem.contains(new Point(e.X, e.Y))) containingItems.Add(placedItem); } if (containingItems.Count > 1) { containingItems.Sort(new zComparer()); //images can overlap, but the mouse click should only go to the top level image/graphic } if (containingItems.Count > 0) //if this is not true than nothing was selected { _selectedItem = containingItems[0]; if (Control.MouseButtons == System.Windows.Forms.MouseButtons.Right) { //?????? should I put this here _showGroupingBox = false; /*if (_selectedItem.selected == false) { _unselectAll(); _selectedItem.selectItem(e, false); }*/ if (_selectedItem.selected) this.showContextMenu(_layoutArea.PointToScreen(e.Location)); } else { if (Control.ModifierKeys == Keys.Control) { //selecting more than one image /* * is selected image already selected? then un-select it * else -> select the image and add it to a list of selected images * * need to check if a single items is group selected and if it is then change it so it is not if only one is left */ if (_selectedItem.selected) { _showGroupingBox = false; _selectedItem.unselectItem(); List<placeableItem> selectedItems = _getSelectedItems(); if (selectedItems.Count == 1) { _selectedItem = selectedItems[0]; _selectedItem.selectItem(e, false); } } else { //if a previous item is selected then change the previous item to a group select if ((previousSelectedItem != null) && (previousSelectedItem != _selectedItem)) { if (previousSelectedItem.selected) previousSelectedItem.selectItem(e, true); } if (previousSelectedItem == null) // only one item is being control clicked { _showGroupingBox = false; _selectedItem.selectItem(e, false); } else { _selectedItem.selectItem(e, true); _showGroupingBox = true; _createGroupingBox(); } } } //end CNTL Modifier Key else //not adding images via CNTL Modifier { if (_selectedItem.groupSelect == false) { _showGroupingBox = false; if ((previousSelectedItem != null) && (previousSelectedItem != _selectedItem)) { previousSelectedItem.unselectItem(); } if (Control.ModifierKeys == Keys.Alt) { } _selectedItem.selectItem(e, false); } else { _showGroupingBox = true; _updateGroupSelectedMousePosition(e); } } } //end not right click } else //the click was not on any image { if ((_GroupingBox != null) && (_groupingRectangle.Contains(e.Location))) { _showGroupingBox = true; _updateGroupSelectedMousePosition(e); } else { _showGroupingBox = false; _GroupingBox = null; List<placeableItem> selectedItems = _getSelectedItems(); foreach (placeableItem selectedItem in selectedItems) { selectedItem.unselectItem(); } _selectedItem = null; } } this.Refresh(); }
public void resizeItem(resizeSelectBox.resizeDirection resizeDirection, float xPerc, float yPerc, Boolean keepAspect) { float aspectRatio = _windowSize_units.Width / _windowSize_units.Height; int fixedX; int fixedY; int newX; int newY; switch (resizeDirection) { case resizeSelectBox.resizeDirection.sW: fixedX = Convert.ToInt16((float)this.location.X + (_windowSize_units.Width * _magnification)); _windowSize_units.Height = _windowSize_units.Height * yPerc; if (!keepAspect) _windowSize_units.Width = _windowSize_units.Width * xPerc; else _windowSize_units.Width = aspectRatio * _windowSize_units.Height; newX = fixedX - Convert.ToInt16(_windowSize_units.Width * _magnification); this.location = new Point(newX, this.location.Y); // _resizingStarted = true; break; case resizeSelectBox.resizeDirection.sE: _windowSize_units.Height = _windowSize_units.Height * yPerc; if (!keepAspect) _windowSize_units.Width = _windowSize_units.Width * xPerc; else _windowSize_units.Width = aspectRatio * _windowSize_units.Height; //_resizingStarted = true; break; case resizeSelectBox.resizeDirection.nE: fixedY = Convert.ToInt16((float)this.location.Y + (_windowSize_units.Height * _magnification)); _windowSize_units.Height = _windowSize_units.Height * yPerc; if (!keepAspect) _windowSize_units.Width = _windowSize_units.Width * xPerc; else _windowSize_units.Width = aspectRatio * _windowSize_units.Height; newY = fixedY - Convert.ToInt16(_windowSize_units.Height * _magnification); this.location = new Point(this.location.X, newY); break; case resizeSelectBox.resizeDirection.nW: fixedX = Convert.ToInt16((float)this.location.X + (_windowSize_units.Width * _magnification)); fixedY = Convert.ToInt16((float)this.location.Y + (_windowSize_units.Height * _magnification)); _windowSize_units.Height = _windowSize_units.Height * yPerc; if (!keepAspect) _windowSize_units.Width = _windowSize_units.Width * xPerc; else _windowSize_units.Width = aspectRatio * _windowSize_units.Height; newX = fixedX - Convert.ToInt16(_windowSize_units.Width * _magnification); newY = fixedY - Convert.ToInt16(_windowSize_units.Height * _magnification); this.location = new Point(newX, newY); break; } _itemAspectRatio = _windowSize_units.Width / _windowSize_units.Height; }
protected void _drawResizeBox(Graphics gfx) { _resizeBox = new resizeSelectBox(this, resizeSelectBox.boxTypes.resize); _resizeBox.draw(gfx); }
void _createGroupingBox(Boolean selectItems) { if (_selectedItems.Count > 1) { int minX = 0; int minY = 0; int maxX = 0; int maxY = 0; int loopCounter = 0; foreach (placeableItem selectedItem in _selectedItems) { if (selectItems) selectedItem.selectItem(mouseDownPosition,true); if (loopCounter == 0) { minX = selectedItem.location.X; minY = selectedItem.location.Y; maxX = selectedItem.location.X + selectedItem.size.Width; maxY = selectedItem.location.Y + selectedItem.size.Height; } else { if (selectedItem.location.X < minX) minX = selectedItem.location.X; if (selectedItem.location.Y < minY) minY = selectedItem.location.Y; if ((selectedItem.location.X + selectedItem.size.Width) > (maxX)) maxX = selectedItem.location.X + selectedItem.size.Width; if ((selectedItem.location.Y + selectedItem.size.Height) > (maxY)) maxY = selectedItem.location.Y + selectedItem.size.Height; } //Console.WriteLine(String.Concat("Item #", loopCounter, " size - w:", selectedItem.size.Width, " h:", selectedItem.size.Height)); loopCounter++; } _groupingRectangle = new Rectangle(new Point(minX, minY), new Size(maxX - minX, maxY - minY)); //Console.WriteLine(String.Concat("GBLoc - (",_groupingRectangle.Location.X,",",_groupingRectangle.Location.Y,") : GBSize - w:",_groupingRectangle.Width," h:",_groupingRectangle.Height)); _GroupingBox = new resizeSelectBox(_groupingRectangle, resizeSelectBox.boxTypes.resize,Color.White); _showGroupingBox = true; } else //no need for groupingBox { if ((_selectedItems.Count == 1) && (selectItems)) _selectedItems[0].selectItem(mouseDownPosition, false); _showGroupingBox = false; } }
public override void draw(Graphics gfx) { Rectangle imageRectangle = _getImageRectangle(); if (_showContainedItem) { _containedItemResizeBox = new resizeSelectBox(imageRectangle, resizeSelectBox.boxTypes.resize, Color.Blue); _containedItemResizeBox.draw(gfx); } Rectangle destRectangle = new Rectangle(this.location, new Size(Convert.ToInt16(_windowSize_units.Width * _magnification), Convert.ToInt16(_windowSize_units.Height * _magnification))); //need some way of keeping existing location if (_autoSizeItem) { this._calculateSourceRectangle(); gfx.DrawImage(this._image, destRectangle, _sourceRectangle, GraphicsUnit.Pixel); } else //not autoFitting image { gfx.DrawImage(this._image, destRectangle); } base.draw(gfx); }