public RuntimeResize() { TopBar = new RuntimeSquare(); LeftBar = new RuntimeSquare(); BottomBar = new RuntimeSquare(); RightBar = new RuntimeSquare(); Action = ResizeAction.Resize; DifEvent = new ResizeDif(DifProc); Q1 = new RuntimeCapture(); Q1.Cursor = Cursors.SizeNWSE; Q2 = new RuntimeCapture(); Q2.Cursor = Cursors.SizeNESW; Q3 = new RuntimeCapture(); Q3.Cursor = Cursors.SizeNWSE; Q4 = new RuntimeCapture(); Q4.Cursor = Cursors.SizeNESW; Q1.OnDif = DifEvent; Q2.OnDif = DifEvent; Q3.OnDif = DifEvent; Q4.OnDif = DifEvent; GridWidth = 100; GridHeight = 100; GridEnabled = false; GridScale = 1; }
private void DifProc(RuntimeCapture sender, int difx, int dify, bool finish, bool start, bool mouseup) { if (start) { return; } int newleft = 0; int newtop = 0; int newwidth = 0; int newheight = 0; bool dosetbounds = true; bool alignleft = false; bool aligntop = false; bool alignbottom = false; bool alignright = false; if (sender == Q1) { newleft = FLeft + difx; newwidth = FWidth - difx; newtop = FTop + dify; newheight = FHeight - dify; alignleft = true; aligntop = true; } if (sender == Q2) { newleft = FLeft; newtop = FTop + dify; newwidth = FWidth + difx; newheight = FHeight - dify; aligntop = true; alignright = true; } if (sender == Q3) { newleft = FLeft; newtop = FTop; newwidth = FWidth + difx; newheight = FHeight + dify; alignright = true; alignbottom = true; } if (sender == Q4) { newleft = FLeft + difx; newtop = FTop; newwidth = FWidth - difx; newheight = FHeight + dify; alignleft = true; alignbottom = true; } if (newwidth < 0) { dosetbounds = false; newleft = newleft - newwidth; newwidth = -newwidth; } if (newheight < 0) { dosetbounds = false; newtop = newtop + newheight; newheight = -newheight; } if (dosetbounds) { // Align to grid if (GridEnabled) { if (alignleft) { newleft = newleft - GridOffsetX; int nleft = Twips.AlignToGridPixels(newleft, GridWidth, GridHeight, GridScale); newwidth = newwidth + newleft - nleft; newleft = nleft; newleft = newleft + GridOffsetX; } if (aligntop) { newtop = newtop - GridOffsetY; int ntop = Twips.AlignToGridPixels(newtop, GridWidth, GridHeight, GridScale); newheight = newheight + newtop - ntop; newtop = ntop; newtop = newtop + GridOffsetY; } if (alignright) { newwidth = newwidth - GridOffsetX + newleft; newwidth = Twips.AlignToGridPixels(newwidth, GridWidth, GridHeight, GridScale); newwidth = newwidth + GridOffsetX - newleft; } if (alignbottom) { newheight = newheight - GridOffsetY + newtop; newheight = Twips.AlignToGridPixels(newheight, GridWidth, GridHeight, GridScale); newheight = newheight + GridOffsetY - newtop; } } SetBounds(newleft, newtop, newwidth, newheight, finish); if (mouseup) { if (OnNewBounds != null) { OnNewBounds(new Rectangle(newleft, newtop, newwidth, newheight)); } } } }