public override void RenderObject() { Point anchor = new Point(0, 0); Font font = Fonts.GetFont(FontID, Zoom.GetFontSize(FontSize), (FontStyle)FontStyle); Graphics g = Graphics.FromHwnd(IntPtr.Zero); g.ApplyGraphicsQuality(); // Measure label size SizeF s = g.MeasureString(ContentTable[Languages.UsedLanguages[0]], font); s = new SizeF((float)Math.Ceiling(s.Width), (float)Math.Ceiling(s.Height)); g.Dispose(); // Is Object Vertical if (IsVertical) { s.Flip(); } Bitmap b = new Bitmap((int)s.Width, (int)s.Height); g = Graphics.FromImage(b); g.ApplyGraphicsQuality(); Point trans = Point.Empty; int angle = 0; if (IsVertical) { if (!IsTurned180) { trans.X = (int)s.Width; } angle += 90; } if (IsTurned180) { if (!IsVertical) { trans = new Point((int)s.Width, (int)s.Height); } else { trans.Y = Funcs.ToInt(s.Height); } angle += 180; } // Apply transformation when label is rotated g.TranslateTransform(trans.X, trans.Y); g.RotateTransform(angle); // Draw the string g.DrawString(ContentTable[Languages.UsedLanguages[0]], font, new SolidBrush(TextColor), Point.Empty); // Remove the transformation for next drawing methods g.ResetTransform(); // Draw the anchor point for this label if (Config.ShowAnchorPoints) { if (IsCenter()) { anchor.X = (int)(s.Width * 0.5F); } if (IsRight()) { anchor.X = (int)s.Width - 1; } if (IsMiddle()) { anchor.Y = (int)(s.Height * 0.5F); } if (IsDown()) { anchor.Y = (int)s.Height - 1; } g.DrawLine(Config.AnchorPen, anchor.X - Config.ANCHOR_SIZE, anchor.Y, anchor.X + Config.ANCHOR_SIZE, anchor.Y); g.DrawLine(Config.AnchorPen, anchor.X, anchor.Y - Config.ANCHOR_SIZE, anchor.X, anchor.Y + Config.ANCHOR_SIZE); } // Release previous rendered bitmap (A lil bit of memore'h :3) if (Holder.Image != null) { Holder.Image.Dispose(); } // Set Canvas Image Holder.Image = b; Holder.Size = Holder.Image.Size; base.RenderObject(); }
public static void OpenProject() { OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.InitialDirectory = Config.LastVisitedPath; fileDialog.Title = "Open a project"; fileDialog.Multiselect = false; fileDialog.Filter = "DocMaker Project (*.dmprj)|*.dmprj"; fileDialog.DefaultExt = "dmprj"; if (fileDialog.ShowDialog() == DialogResult.OK) { //Save last opened directory Config.LastVisitedPath = Path.GetDirectoryName(fileDialog.FileName); if (!File.Exists(fileDialog.FileName)) { Funcs.Error("Project file not found !"); return; } if (changeList.Count > 0) { DialogResult dr = Funcs.Question_YNC("Do you want to save changes before opening the file ?"); if (dr == DialogResult.Cancel) { return; } if (dr == DialogResult.Yes) { SaveProject(); } } // Save the file projectLoadedFromFile = true; projectFile = fileDialog.FileName; projectTitle = Path.GetFileName(projectFile); try { InitializeComponents(); fileHandler = new BinaryFileHandler(projectFile, BinaryFileHandler.FileMode.READ); Paper.LoadPaper(); Fonts.LoadFonts(); Languages.LoadLanguages(); Resources.LoadResources(); Objects.LoadObjects(); fileHandler.Close(); } catch (Exception ex) { Funcs.Error("Error while loading the project file.\n" + ex.Message); fileHandler.Close(); // Force closing file NewProject(); } } }
protected override void OnMouseWheel(MouseEventArgs e) { if (UsedFilter == Filter.DigitsOnly) { int newValue = Funcs.ToInt(this.Text) + (Wheel_StepValue * Funcs.Force(Funcs.ToInt(e.Delta))); if (!IgnoreClampig) { this.Text = Funcs.Clamp(newValue, MinimumValue, MaximumValue).ToString(); } this.Select(this.Text.Length, 0); } base.OnMouseWheel(e); }
private void Canvas_MouseMove(object sender, MouseEventArgs e) { //Point s = new Point(200, 200); Point s; if (isMouseDown) { //X = X - mouseLastLocation.X + e.X; //Y = Y - mouseLastLocation.Y + e.Y; /* * // Calcualte the Canvas's new location * Point newLocation = new Point(RealLocation.X - mouseLastLocation.X + e.X, * RealLocation.Y - mouseLastLocation.Y + e.Y); * * Size halfCanvas = new Size((int)((float)Canvas.Width / 2.0f), * (int)((float)Canvas.Height / 2.0f)); * * Point canvasLocation = Point.Empty; * * if(IsLeft()) * { * newLocation.X = Funcs.Clamp(newLocation.X, 0, Zoom.paperSize.Width - Canvas.Width); * canvasLocation.X = newLocation.X; * } * else if(IsCenter()) * { * newLocation.X = Funcs.Clamp(newLocation.X, halfCanvas.Width, Zoom.paperSize.Width - halfCanvas.Width); * canvasLocation.X = newLocation.X - halfCanvas.Width; * } * else if(IsRight()) * { * newLocation.X = Funcs.Clamp(newLocation.X, Canvas.Width, Zoom.paperSize.Width); * canvasLocation.X = newLocation.X - Canvas.Width; * } * * if (IsUp()) * { * newLocation.Y = Funcs.Clamp(newLocation.Y, 0, Zoom.paperSize.Height - Canvas.Height); * canvasLocation.Y = newLocation.Y; * } * else if (IsMiddle()) * { * newLocation.Y = Funcs.Clamp(newLocation.Y, halfCanvas.Height, Zoom.paperSize.Height - halfCanvas.Height); * canvasLocation.Y = newLocation.Y - halfCanvas.Height; * } * else if (IsDown()) * { * newLocation.Y = Funcs.Clamp(newLocation.Y, Canvas.Height, Zoom.paperSize.Height); * canvasLocation.Y = newLocation.Y - Canvas.Height; * } * * * RealLocation = newLocation; * * Canvas.Location = Zoom.Calculate(canvasLocation); * Canvas.Update(); * */ // Calcualte the Canvas's new location Point p = new Point(Holder.Location.X - mouseLastLocation.X + e.X, Holder.Location.Y - mouseLastLocation.Y + e.Y); // Ignore snapping and alignment if control is pressed if (Control.ModifierKeys != Keys.Control && e.Button != MouseButtons.Right) { // A Basic snapping Algorithm foreach (DocumentObject obj in Objects.objectList) { if (obj == this || !obj.Visible) { continue; } s = obj.Holder.Location; if (p.X >= s.X - 10 && p.X < s.X + 10) { p.X = s.X; } if (p.Y >= s.Y - 10 && p.Y < s.Y + 10) { p.Y = s.Y; } } } // Always clamp Position to inside the document p.X = Funcs.Clamp(p.X, 0, Zoom.paperSize.Width - Holder.Width); p.Y = Funcs.Clamp(p.Y, 0, Zoom.paperSize.Height - Holder.Height); Holder.Location = p; Holder.Update(); RecalculateRealPosition(); // Update position labels on the main form LivePreview.mainForm.UpdateObjectPosition(); } }