void LoadRTFNotices() { DirectoryInfo DI = new DirectoryInfo(NoticeFilesLocation); if (DI.Exists) { List <FileInfo> img_files = DI.GetFiles("*.rtf").ToList(); img_files.ForEach(f => { if (f.Exists) { RichTextNotice notice = new RichTextNotice(); notice.FileLocation = f.FullName; notice.LastWriteTime = f.LastWriteTime; notice.Width = 1654; notice.Height = 2338; Notices.Add(notice); } }); } }
public void ArrangeNotices() { NoticeUIElements.Clear(); double canvas_width = CanvasNotices.ActualWidth; double canvas_height = CanvasNotices.ActualHeight; double canvas_aspect_ratio = canvas_width / canvas_height; int min_area_needed_in_blocks = Notices.Sum(n => n.AreaInBlocks); int min_height = Notices.Max(n => n.HeightInBlocks); int min_width = Notices.Max(n => n.WidthInBlocks); double d_canvas_block_height = Math.Sqrt((double)min_area_needed_in_blocks / canvas_aspect_ratio); if (d_canvas_block_height < min_height) { d_canvas_block_height = min_height; } double d_canvas_block_width = d_canvas_block_height * canvas_aspect_ratio; if (d_canvas_block_width < min_width) { d_canvas_block_width = min_width; } int canvas_block_width = (int)Math.Ceiling(d_canvas_block_width); int canvas_block_height = (int)Math.Ceiling(d_canvas_block_height); double grid_size = canvas_width / canvas_block_width; Box2D[] b2ds = Notices.Select(n => new Box2D(0, 0, n.WidthInBlocks, n.HeightInBlocks) { Tag = n }).ToArray(); TLABS.BinPacking.Algorithms.SubAlgFillOneColumn(canvas_block_width, b2ds); GlobalScaleFactor = grid_size / Notice.BlockSize; int max_w = b2ds.Max(b => b.Right); int max_h = b2ds.Max(b => b.Bottom); if (max_h > canvas_block_height) { double scale = (double)canvas_block_height / (double)(max_h + 1); GlobalScaleFactor *= scale; grid_size *= scale; } int wblocks = (int)(canvas_width / grid_size); double left_margin = ((wblocks - max_w) / 2.0) * grid_size; foreach (Box2D box in b2ds) { Notice n = box.Tag as Notice; Border b = new Border(); b.Width = (box.Width - 2) * grid_size; b.Height = (box.Height - 2) * grid_size; if (n is ScannedNotice) { b.Background = new ImageBrush() { ImageSource = ((ScannedNotice)n).Image }; //b.Background = new SolidColorBrush(Colors.Red); } else if (n is RichTextNotice) { RichTextNotice rtn = n as RichTextNotice; string fileName = rtn.FileLocation; RichTextBox rtb = new RichTextBox(); TextRange range; if (File.Exists(fileName)) { range = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd); using (FileStream f_stream = new FileStream(fileName, FileMode.OpenOrCreate)) { range.Load(f_stream, DataFormats.Rtf); } } b.Child = rtb; rtb.IsReadOnly = true; rtb.Background = new ImageBrush() { ImageSource = (BitmapImage)this.Resources["PaperTexture"], TileMode = TileMode.Tile }; rtb.Width = n.Width; rtb.Height = n.Height; rtb.Padding = new Thickness(200, 200, 200, 200); rtb.LayoutTransform = new ScaleTransform() { ScaleX = b.Width / rtb.Width, ScaleY = b.Height / rtb.Height }; } double left = left_margin + (box.X + 1) * grid_size; double top = (box.Y + 1) * grid_size; b.SetValue(Canvas.LeftProperty, left); b.SetValue(Canvas.TopProperty, top); b.Effect = new DropShadowEffect() { ShadowDepth = 3, Direction = GetShadowDirection(box.X + box.Width / 2, box.Y + box.Height / 2, max_w, max_h), BlurRadius = 5, Opacity = 0.5 }; ScaleTransform st = new ScaleTransform(); TransformGroup tg = new TransformGroup(); tg.Children.Add(st); b.RenderTransform = tg; //b.CacheMode = new BitmapCache() { RenderAtScale = 1 / GlobalScaleFactor , SnapsToDevicePixels=false}; CanvasNotices.Children.Add(b); if (NoticeUIElements.ContainsKey(n)) { NoticeUIElements[n] = b; } else { NoticeUIElements.Add(n, b); } #region Add push pin Image img_pushpin = GetRandomPushPinImage(); img_pushpin.Width = 50 * GlobalScaleFactor; img_pushpin.Height = 50 * GlobalScaleFactor; img_pushpin.SetValue(Canvas.LeftProperty, left - (25 * GlobalScaleFactor) + (b.Width / 2.0)); img_pushpin.SetValue(Canvas.TopProperty, top); CanvasNotices.Children.Add(img_pushpin); #endregion this.Wall.CacheMode = new BitmapCache() { RenderAtScale = 1 / GlobalScaleFactor }; } }