Пример #1
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            if (borderColor.Alpha0To255 > 0)
            {
                RectangleDouble borderRectangle = LocalBounds;

                if (borderWidth > 0)
                {
                    if (borderWidth == 1)
                    {
                        graphics2D.Rectangle(borderRectangle, borderColor);
                    }
                    else
                    {
                        //boarderRectangle.Inflate(-borderWidth / 2);
                        RoundedRect rectBorder = new RoundedRect(borderRectangle, this.borderRadius);

                        graphics2D.Render(new Stroke(rectBorder, borderWidth), borderColor);
                    }
                }
            }

            if (this.fillColor.Alpha0To255 > 0)
            {
                RectangleDouble insideBounds = LocalBounds;
                insideBounds.Inflate(-this.borderWidth);
                RoundedRect rectInside = new RoundedRect(insideBounds, Math.Max(this.borderRadius - this.borderWidth, 0));

                graphics2D.Render(rectInside, this.fillColor);
            }

            base.OnDraw(graphics2D);
        }
Пример #2
0
            internal SwitchView(double width, double height, bool startValue, Color backgroundColor, Color interiorColor, Color thumbColor, Color exteriorColor, Color borderColor)
            {
                this.Checked = startValue;

                var thumbHeight = height;
                var thumbWidth  = 14;

                InteriorColor = interiorColor;
                ExteriorColor = exteriorColor;

                this.borderColor = borderColor;

                disabledBorderColor = new Color(borderColor, 50);

                ThumbColor  = thumbColor;
                LocalBounds = new RectangleDouble(0, 0, width, height);

                this.switchBounds = new RectangleDouble(0, 0, width, height);

                innerRect = this.switchBounds;
                innerRect.Inflate(new BorderDouble(-3, -6));

                borderRect = this.switchBounds;
                borderRect.Inflate(new BorderDouble(0, -3));

                checkedThumbBounds   = new RectangleDouble(width - thumbWidth, 0, width, thumbHeight);
                uncheckedThumbBounds = new RectangleDouble(0, 0, thumbWidth, thumbHeight);
            }
Пример #3
0
        private void CreateBase(List <MeshGroup> meshesList, List <Matrix4X4> meshTransforms, List <PlatingMeshGroupData> platingDataList)
        {
            if (meshesList.Count > 0)
            {
                AxisAlignedBoundingBox bounds = meshesList[0].GetAxisAlignedBoundingBox(meshTransforms[0]);
                for (int i = 1; i < meshesList.Count; i++)
                {
                    bounds = AxisAlignedBoundingBox.Union(bounds, meshesList[i].GetAxisAlignedBoundingBox(meshTransforms[i]));
                }

                double          roundingScale = 20;
                RectangleDouble baseRect      = new RectangleDouble(bounds.minXYZ.x, bounds.minXYZ.y, bounds.maxXYZ.x, bounds.maxXYZ.y);
                baseRect.Inflate(2);
                baseRect *= roundingScale;
                RoundedRect baseRoundedRect = new RoundedRect(baseRect, 1 * roundingScale);

                Mesh baseMeshResult = VertexSourceToMesh.Extrude(baseRoundedRect, unscaledBaseHeight / 2 * roundingScale * sizeScrollBar.Value * heightScrollBar.Value);

                baseMeshResult.Transform(Matrix4X4.CreateScale(1 / roundingScale));

                meshesList.Add(new MeshGroup(baseMeshResult));
                platingDataList.Add(new PlatingMeshGroupData());
                meshTransforms.Add(Matrix4X4.CreateTranslation(0, 0, 0));
                PlatingHelper.CreateITraceableForMeshGroup(platingDataList, meshesList, meshesList.Count - 1, null);
            }
        }
Пример #4
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            CheckBox checkBox = (CheckBox)Parent;

            double bottom = 0;

            // the check
            if (checkBox.Checked)
            {
                graphics2D.Line(new Vector2(1, CheckBoxWidth + bottom), new Vector2(1 + CheckBoxWidth, 0 + bottom), this.TextColor);
                graphics2D.Line(new Vector2(1, 0 + bottom), new Vector2(1 + CheckBoxWidth, CheckBoxWidth + bottom), this.TextColor);
            }

            // the frame
            RectangleDouble clampedRect = new RectangleDouble(1, Math.Floor(0 + bottom), 1 + Math.Ceiling(CheckBoxWidth), Math.Ceiling(CheckBoxWidth + bottom));

            graphics2D.Rectangle(clampedRect, this.TextColor);

            // extra frame
            if (checkBox.MouseDownOnButton && checkBox.FirstWidgetUnderMouse)
            {
                clampedRect.Inflate(1);
                graphics2D.Rectangle(clampedRect, this.TextColor);
            }

            base.OnDraw(graphics2D);
        }
Пример #5
0
        public void DoDrawAfterChildren(Graphics2D graphics2D)
        {
            RoundedRect track = new RoundedRect(GetTrackBounds(), TrackHeight / 2);
            Vector2     ValuePrintPosition;

            if (sliderAttachedTo.Orientation == Orientation.Horizontal)
            {
                ValuePrintPosition = new Vector2(sliderAttachedTo.TotalWidthInPixels / 2, -sliderAttachedTo.ThumbHeight - 12);
            }
            else
            {
                ValuePrintPosition = new Vector2(0, -sliderAttachedTo.ThumbHeight - 12);
            }

            // draw the track
            graphics2D.Render(track, TrackColor);

            // now do the thumb
            RectangleDouble thumbBounds  = sliderAttachedTo.GetThumbHitBounds();
            RoundedRect     thumbOutside = new RoundedRect(thumbBounds, sliderAttachedTo.ThumbWidth / 2);

            graphics2D.Render(thumbOutside, RGBA_Floats.GetTweenColor(ThumbColor.GetAsRGBA_Floats(), RGBA_Floats.Black.GetAsRGBA_Floats(), .2).GetAsRGBA_Bytes());
            thumbBounds.Inflate(-1);
            RoundedRect thumbInside = new RoundedRect(thumbBounds, sliderAttachedTo.ThumbWidth / 2);

            graphics2D.Render(thumbInside, ThumbColor);
        }
Пример #6
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            if (Parent is CheckBox checkBox)
            {
                double bottom = LocalBounds.Bottom + (Height / 2 - CheckBoxWidth / 2);

                // the check
                if (checkBox.Checked)
                {
                    graphics2D.Line(new Vector2(1, CheckBoxWidth + bottom), new Vector2(1 + CheckBoxWidth, 0 + bottom), this.TextColor);
                    graphics2D.Line(new Vector2(1, 0 + bottom), new Vector2(1 + CheckBoxWidth, CheckBoxWidth + bottom), this.TextColor);
                }

                // the frame
                RectangleDouble clampedRect = new RectangleDouble(1, Math.Floor(0 + bottom), 1 + Math.Ceiling(CheckBoxWidth), Math.Ceiling(CheckBoxWidth + bottom));
                graphics2D.Rectangle(clampedRect, this.TextColor);

                // extra frame
                if (checkBox.MouseDownOnWidget && checkBox.FirstWidgetUnderMouse)
                {
                    clampedRect.Inflate(1);
                    graphics2D.Rectangle(clampedRect, this.TextColor);
                }
            }

            base.OnDraw(graphics2D);
        }
Пример #7
0
        internal void ValidateScrollPosition()
        {
            var parent = this.Parent;

            if (parent == null)
            {
                return;
            }

            Vector2 newOrigin = OriginRelativeParent;

            Vector2 topLeftOffset = parentScrollableWidget.TopLeftOffset;

            RectangleDouble boundsWithMargin = LocalBounds;

            boundsWithMargin.Inflate(Margin);
            if (boundsWithMargin.Height < parentScrollableWidget.LocalBounds.Height)
            {
                debugRecursionCount++;
                if (debugRecursionCount < 20)
                {
                    parentScrollableWidget.TopLeftOffset = new Vector2(parentScrollableWidget.TopLeftOffset.X, 0);
                }

                debugRecursionCount--;
                newOrigin.Y = OriginRelativeParent.Y;
            }
            else
            {
                if (newOrigin.Y + Margin.Top + Padding.Top + LocalBounds.Top < parent.LocalBounds.Top)
                {
                    newOrigin.Y = parent.LocalBounds.Top - Margin.Top - Padding.Top - LocalBounds.Top;
                }
                else if (LocalBounds.Height + Margin.Height >= parent.LocalBounds.Height)
                {
                    if (BoundsRelativeToParent.Bottom - Margin.Bottom > parent.LocalBounds.Bottom)
                    {
                        newOrigin.Y = parent.LocalBounds.Bottom - LocalBounds.Bottom + Margin.Bottom;
                    }
                }
            }

            if (BoundsRelativeToParent.Left - Margin.Left > parent.LocalBounds.Left)
            {
                newOrigin.X = parent.LocalBounds.Left - LocalBounds.Left + Margin.Left;
            }
            else if (LocalBounds.Width + Margin.Width > parent.LocalBounds.Width)
            {
                if (BoundsRelativeToParent.Right + Margin.Right < parent.LocalBounds.Right)
                {
                    newOrigin.X = parent.LocalBounds.Right - LocalBounds.Right - Margin.Right;
                }
            }

            if (newOrigin != OriginRelativeParent)
            {
                OriginRelativeParent = newOrigin;
            }
        }
Пример #8
0
        private void PrimeHotend(GCodeSketch gcodeSketch, RectangleDouble towerRect)
        {
            gcodeSketch.WriteRaw("; Priming");

            while (towerRect.Width > 4)
            {
                towerRect.Inflate(-nozzleWidth);
                gcodeSketch.DrawRectangle(towerRect);
            }
        }
Пример #9
0
        private RectangleDouble CreatePerimeters(GCodeSketch gcodeSketch, RectangleDouble rect)
        {
            gcodeSketch.WriteRaw("; CreatePerimeters");
            for (var i = 0; i < 3; i++)
            {
                rect.Inflate(-nozzleWidth);
                gcodeSketch.DrawRectangle(rect);
            }

            return(rect);
        }
Пример #10
0
        private void DrawBackground(Graphics2D graphics2D)
        {
            if (this.fillColor.Alpha0To255 > 0)
            {
                RectangleDouble insideBounds = LocalBounds;
                insideBounds.Inflate(-this.borderWidth);
                RoundedRect rectInside = new RoundedRect(insideBounds, 0);

                graphics2D.Render(rectInside, this.fillColor);
            }
        }
        private void LoadStl_Click(object sender, EventArgs e)
        {
            OpenFileDialogParams opeParams = new OpenFileDialogParams("STL Files|*.stl");

            FileDialog.OpenFileDialog(opeParams, (openParams) =>
            {
                var streamToLoadFrom = File.Open(openParams.FileName, FileMode.Open);

                if (streamToLoadFrom != null)
                {
                    var loadedFileName = openParams.FileName;

                    meshToRender = StlProcessing.Load(streamToLoadFrom);

                    ImageBuffer plateInventory = new ImageBuffer((int)(300 * 8.5), 300 * 11, 32, new BlenderBGRA());
                    Graphics2D plateGraphics   = plateInventory.NewGraphics2D();
                    plateGraphics.Clear(RGBA_Bytes.White);

                    double inchesPerMm          = 0.0393701;
                    double pixelsPerInch        = 300;
                    double pixelsPerMm          = inchesPerMm * pixelsPerInch;
                    AxisAlignedBoundingBox aabb = meshToRender.GetAxisAlignedBoundingBox();
                    Vector2 lowerLeftInMM       = new Vector2(-aabb.minXYZ.x, -aabb.minXYZ.y);
                    Vector3 centerInMM          = (aabb.maxXYZ - aabb.minXYZ) / 2;
                    Vector2 offsetInMM          = new Vector2(20, 30);

                    {
                        RectangleDouble bounds = new RectangleDouble(offsetInMM.x * pixelsPerMm,
                                                                     offsetInMM.y * pixelsPerMm,
                                                                     (offsetInMM.x + aabb.maxXYZ.x - aabb.minXYZ.x) * pixelsPerMm,
                                                                     (offsetInMM.y + aabb.maxXYZ.y - aabb.minXYZ.y) * pixelsPerMm);
                        bounds.Inflate(3 * pixelsPerMm);
                        RoundedRect rect = new RoundedRect(bounds, 3 * pixelsPerMm);
                        plateGraphics.Render(rect, RGBA_Bytes.LightGray);
                        Stroke rectOutline = new Stroke(rect, .5 * pixelsPerMm);
                        plateGraphics.Render(rectOutline, RGBA_Bytes.DarkGray);
                    }

                    OrthographicZProjection.DrawTo(plateGraphics, meshToRender, lowerLeftInMM + offsetInMM, pixelsPerMm);
                    plateGraphics.DrawString(Path.GetFileName(openParams.FileName), (offsetInMM.x + centerInMM.x) * pixelsPerMm, (offsetInMM.y - 10) * pixelsPerMm, 50, Agg.Font.Justification.Center);

                    //ImageBuffer logoImage = new ImageBuffer();
                    //ImageIO.LoadImageData("Logo.png", logoImage);
                    //plateGraphics.Render(logoImage, (plateInventory.Width - logoImage.Width) / 2, plateInventory.Height - logoImage.Height - 10 * pixelsPerMm);

                    //ImageIO.SaveImageData("plate Inventory.jpeg", plateInventory);
                }
            });
        }
Пример #12
0
        public void DrawAfterChildren(Graphics2D graphics2D)
        {
            if (SwitchState)
            {
                RectangleDouble interior = GetSwitchBounds();
                interior.Inflate(-6);
                graphics2D.FillRectangle(interior, InteriorColor);
            }
            RectangleDouble border = GetSwitchBounds();

            border.Inflate(-3);
            graphics2D.Rectangle(border, ExteriorColor, 1);
            graphics2D.FillRectangle(GetThumbBounds(), ThumbColor);
            graphics2D.Rectangle(GetThumbBounds(), new RGBA_Bytes(255, 255, 255, 90), 1);
        }
Пример #13
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            RectangleDouble Bounds     = LocalBounds;
            RoundedRect     rectBorder = new RoundedRect(Bounds, this.borderRadius);

            graphics2D.Render(rectBorder, BorderColor);

            RectangleDouble insideBounds = Bounds;

            insideBounds.Inflate(-this.borderWidth);
            RoundedRect rectInside = new RoundedRect(insideBounds, Math.Max(this.borderRadius - this.borderWidth, 0));

            graphics2D.Render(rectInside, this.BackgroundColor);
            base.OnDraw(graphics2D);
        }
Пример #14
0
            public override void OnDraw(Graphics2D graphics2D)
            {
                graphics2D.FillRectangle(GetSwitchBounds(), BackgroundColor);
                base.OnDraw(graphics2D);
                if (startValue)
                {
                    RectangleDouble interior = GetSwitchBounds();
                    interior.Inflate(-6);
                    graphics2D.FillRectangle(interior, InteriorColor);
                }
                RectangleDouble border = GetSwitchBounds();

                border.Inflate(-3);
                graphics2D.Rectangle(border, ExteriorColor, 1);
                graphics2D.FillRectangle(GetThumbBounds(), ThumbColor);
                graphics2D.Rectangle(GetThumbBounds(), new RGBA_Bytes(255, 255, 255, 90), 1);
            }
Пример #15
0
        public void DoDrawAfterChildren(Graphics2D graphics2D)
        {
            var track = new RoundedRect(GetTrackBounds(), TrackHeight / 2);

            // draw the track
            graphics2D.Render(track, TrackColor);

            // now do the thumb
            RectangleDouble thumbBounds  = sliderAttachedTo.GetThumbHitBounds();
            var             thumbOutside = new RoundedRect(thumbBounds, sliderAttachedTo.ThumbWidth / 2);

            graphics2D.Render(thumbOutside, ColorF.GetTweenColor(ThumbColor.ToColorF(), ColorF.Black.ToColorF(), .2).ToColor());
            thumbBounds.Inflate(-1);
            var thumbInside = new RoundedRect(thumbBounds, sliderAttachedTo.ThumbWidth / 2);

            graphics2D.Render(thumbInside, ThumbColor);
        }
Пример #16
0
        public Vector2 RatioOfViewToContents0To1()
        {
            Vector2         ratio = Vector2.Zero;
            RectangleDouble boundsOfScrollableContents = ScrollArea.LocalBounds;

            boundsOfScrollableContents.Inflate(ScrollArea.Margin);             // expand it by margin as that is how much it is allowed to move

            if (boundsOfScrollableContents.Width > 0)
            {
                ratio.x = Math.Max(0, Math.Min(1, Width / boundsOfScrollableContents.Width));
            }
            if (boundsOfScrollableContents.Height > 0)
            {
                ratio.y = Math.Max(0, Math.Min(1, Height / boundsOfScrollableContents.Height));
            }

            return(ratio);
        }
Пример #17
0
        public static void Fit(this WorldView world, IObject3D itemToRender, RectangleDouble goalBounds, Matrix4X4 offset)
        {
            AxisAlignedBoundingBox meshBounds = itemToRender.GetAxisAlignedBoundingBox(offset);

            bool   done          = false;
            double scaleFraction = .1;

            // make the target size a portion of the total size
            goalBounds.Inflate(-goalBounds.Width * .1);

            int rescaleAttempts = 0;

            while (!done && rescaleAttempts++ < 500)
            {
                RectangleDouble partScreenBounds = GetScreenBounds(meshBounds, world);

                if (!NeedsToBeSmaller(partScreenBounds, goalBounds))
                {
                    world.Scale     *= (1 + scaleFraction);
                    partScreenBounds = GetScreenBounds(meshBounds, world);

                    // If it crossed over the goal reduct the amount we are adjusting by.
                    if (NeedsToBeSmaller(partScreenBounds, goalBounds))
                    {
                        scaleFraction /= 2;
                    }
                }
                else
                {
                    world.Scale     *= (1 - scaleFraction);
                    partScreenBounds = GetScreenBounds(meshBounds, world);

                    // If it crossed over the goal reduct the amount we are adjusting by.
                    if (!NeedsToBeSmaller(partScreenBounds, goalBounds))
                    {
                        scaleFraction /= 2;
                        if (scaleFraction < .001)
                        {
                            done = true;
                        }
                    }
                }
            }
        }
Пример #18
0
        private void ScaleMeshToView(List <MeshGroup> loadedMeshGroups)
        {
            if (loadedMeshGroups != null)
            {
                AxisAlignedBoundingBox meshBounds = GetAxisAlignedBoundingBox(loadedMeshGroups);

                bool            done          = false;
                double          scaleFraction = .1;
                RectangleDouble goalBounds    = new RectangleDouble(0, 0, size.x, size.y);
                goalBounds.Inflate(-10);
                while (!done)
                {
                    RectangleDouble partScreenBounds = GetScreenBounds(meshBounds);

                    if (!NeedsToBeSmaller(partScreenBounds, goalBounds))
                    {
                        trackballTumbleWidget.TrackBallController.Scale *= (1 + scaleFraction);
                        partScreenBounds = GetScreenBounds(meshBounds);

                        // If it crossed over the goal reduct the amount we are adjusting by.
                        if (NeedsToBeSmaller(partScreenBounds, goalBounds))
                        {
                            scaleFraction /= 2;
                        }
                    }
                    else
                    {
                        trackballTumbleWidget.TrackBallController.Scale *= (1 - scaleFraction);
                        partScreenBounds = GetScreenBounds(meshBounds);

                        // If it crossed over the goal reduct the amount we are adjusting by.
                        if (!NeedsToBeSmaller(partScreenBounds, goalBounds))
                        {
                            scaleFraction /= 2;
                            if (scaleFraction < .001)
                            {
                                done = true;
                            }
                        }
                    }
                }
            }
        }
        public static Vector2 EnsureInPrintBounds(PrinterConfig printer, Vector2 probePosition)
        {
            // check that the position is within the printing area and if not move it back in
            if (printer.Settings.Helpers.UseZProbe())
            {
                var probeOffset2D        = new Vector2(printer.Settings.GetValue <Vector3>(SettingsKey.probe_offset));
                var actualNozzlePosition = probePosition - probeOffset2D;

                // clamp this to the bed bounds
                Vector2 bedSize     = printer.Settings.GetValue <Vector2>(SettingsKey.bed_size);
                Vector2 printCenter = printer.Settings.GetValue <Vector2>(SettingsKey.print_center);
                var     bedBounds   = new RectangleDouble(printCenter - bedSize / 2, printCenter + bedSize / 2);
                bedBounds.Inflate(-1);
                Vector2 adjustedPosition = bedBounds.Clamp(actualNozzlePosition);

                // and push it back into the probePosition
                probePosition = adjustedPosition + probeOffset2D;
            }

            return(probePosition);
        }
Пример #20
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            GuiWidget parentButton = Parent;

            RectangleDouble Bounds = LocalBounds;

            RoundedRect rectBorder = new RoundedRect(Bounds, BorderRadius);

            if (parentButton.Enabled == true)
            {
                graphics2D.Render(rectBorder, new Color(0, 0, 0));
            }
            else
            {
                graphics2D.Render(rectBorder, new Color(128, 128, 128));
            }

            RectangleDouble insideBounds = Bounds;

            insideBounds.Inflate(-BorderWidth);

            RoundedRect rectInside  = new RoundedRect(insideBounds, Math.Max(BorderRadius - BorderWidth, 0));
            Color       insideColor = new Color(1.0, 1.0, 1.0);

            if (parentButton.FirstWidgetUnderMouse)
            {
                if (parentButton.MouseDownOnWidget)
                {
                    insideColor = DefaultViewFactory.DefaultBlue;
                }
                else
                {
                    insideColor = DefaultViewFactory.DefaultBlue.ToColorF().Blend(ColorF.White, .75).ToColor();
                }
            }

            graphics2D.Render(rectInside, insideColor);

            base.OnDraw(graphics2D);
        }
Пример #21
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            Button parentButton = (Button)Parent;

            RectangleDouble Bounds = LocalBounds;

            RoundedRect rectBorder = new RoundedRect(Bounds, BorderRadius);

            if (parentButton.Enabled == true)
            {
                graphics2D.Render(rectBorder, new RGBA_Bytes(0, 0, 0));
            }
            else
            {
                graphics2D.Render(rectBorder, new RGBA_Bytes(128, 128, 128));
            }
            RectangleDouble insideBounds = Bounds;

            insideBounds.Inflate(-BorderWidth);
            RoundedRect rectInside  = new RoundedRect(insideBounds, Math.Max(BorderRadius - BorderWidth, 0));
            RGBA_Bytes  insideColor = new RGBA_Bytes(1.0, 1.0, 1.0);

            if (parentButton.FirstWidgetUnderMouse)
            {
                if (parentButton.MouseDownOnButton)
                {
                    insideColor = DefaultViewFactory.DefaultBlue;
                }
                else
                {
                    insideColor = DefaultViewFactory.DefaultBlue.GetAsRGBA_Floats().Blend(RGBA_Floats.White, .75).GetAsRGBA_Bytes();
                }
            }

            graphics2D.Render(rectInside, insideColor);

            base.OnDraw(graphics2D);
        }
Пример #22
0
        public override void OnDraw(Agg.Graphics2D graphics2D)
        {
            RectangleDouble Bounds     = LocalBounds;
            RoundedRect     rectBorder = new RoundedRect(Bounds, this.borderRadius);

            graphics2D.Render(rectBorder, borderColor);

            RectangleDouble insideBounds = Bounds;

            insideBounds.Inflate(-this.borderWidth);
            RoundedRect rectInside = new RoundedRect(insideBounds, Math.Max(this.borderRadius - this.borderWidth, 0));

            graphics2D.Render(rectInside, this.fillColor);

            if (this.isUnderlined)
            {
                //Printer.TypeFaceStyle.DoUnderline = true;
                RectangleDouble underline = new RectangleDouble(LocalBounds.Left, LocalBounds.Bottom, LocalBounds.Right, LocalBounds.Bottom);
                graphics2D.Rectangle(underline, buttonText.TextColor);
            }

            base.OnDraw(graphics2D);
        }
Пример #23
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            double fontHeight = internalTextWidget.Printer.TypeFaceStyle.EmSizeInPixels;

            if (Selecting &&
                SelectionIndexToStartBefore != CharIndexToInsertBefore)
            {
                Vector2 selectPosition = internalTextWidget.Printer.GetOffsetLeftOfCharacterIndex(SelectionIndexToStartBefore);

                // for each selected line draw a rect for the chars of that line
                if (selectPosition.Y == InsertBarPosition.Y)
                {
                    var bar = new RectangleDouble(Math.Ceiling(selectPosition.X),
                                                  Math.Ceiling(internalTextWidget.Height + selectPosition.Y),
                                                  Math.Ceiling(InsertBarPosition.X + 1),
                                                  Math.Ceiling(internalTextWidget.Height + InsertBarPosition.Y - fontHeight));

                    var selectCursorRect = new RoundedRect(bar, 0);
                    graphics2D.Render(selectCursorRect, this.HighlightColor);
                }
                else
                {
                    int     firstCharToHighlight = Math.Min(CharIndexToInsertBefore, SelectionIndexToStartBefore);
                    int     lastCharToHighlight  = Math.Max(CharIndexToInsertBefore, SelectionIndexToStartBefore);
                    int     lineStart            = firstCharToHighlight;
                    Vector2 lineStartPos         = internalTextWidget.Printer.GetOffsetLeftOfCharacterIndex(lineStart);
                    int     lineEnd    = lineStart + 1;
                    Vector2 lineEndPos = internalTextWidget.Printer.GetOffsetLeftOfCharacterIndex(lineEnd);
                    if (lineEndPos.Y != lineStartPos.Y)
                    {
                        // we are starting on a '\n', adjust so we will show the cr at the end of the line
                        lineEndPos = lineStartPos;
                    }

                    bool firstCharOfLine = false;
                    for (int i = lineEnd; i < lastCharToHighlight + 1; i++)
                    {
                        Vector2 nextPos = internalTextWidget.Printer.GetOffsetLeftOfCharacterIndex(i);
                        if (firstCharOfLine)
                        {
                            if (lineEndPos.Y != lineStartPos.Y)
                            {
                                // we are starting on a '\n', adjust so we will show the cr at the end of the line
                                lineEndPos = lineStartPos;
                            }

                            firstCharOfLine = false;
                        }

                        if (nextPos.Y != lineStartPos.Y)
                        {
                            if (lineEndPos.X == lineStartPos.X)
                            {
                                lineEndPos.X += Printer.TypeFaceStyle.GetAdvanceForCharacter(' ');
                            }

                            var bar = new RectangleDouble(Math.Ceiling(lineStartPos.X),
                                                          Math.Ceiling(internalTextWidget.Height + lineStartPos.Y),
                                                          Math.Ceiling(lineEndPos.X + 1),
                                                          Math.Ceiling(internalTextWidget.Height + lineEndPos.Y - fontHeight));

                            var selectCursorRect = new RoundedRect(bar, 0);
                            graphics2D.Render(selectCursorRect, this.HighlightColor);
                            lineStartPos    = nextPos;
                            firstCharOfLine = true;
                        }
                        else
                        {
                            lineEndPos = nextPos;
                        }
                    }

                    if (lineEndPos.X != lineStartPos.X)
                    {
                        var bar = new RectangleDouble(Math.Ceiling(lineStartPos.X),
                                                      Math.Ceiling(internalTextWidget.Height + lineStartPos.Y),
                                                      Math.Ceiling(lineEndPos.X + 1),
                                                      Math.Ceiling(internalTextWidget.Height + lineEndPos.Y - fontHeight));

                        var selectCursorRect = new RoundedRect(bar, 0);
                        graphics2D.Render(selectCursorRect, this.HighlightColor);
                    }
                }
            }

            if (this.Focused && BarIsShowing)
            {
                double xFraction = graphics2D.GetTransform().tx;
                xFraction = xFraction - (int)xFraction;
                var bar2 = new RectangleDouble(Math.Ceiling(InsertBarPosition.X) - xFraction,
                                               Math.Ceiling(internalTextWidget.Height + InsertBarPosition.Y - fontHeight),
                                               Math.Ceiling(InsertBarPosition.X + 1) - xFraction,
                                               Math.Ceiling(internalTextWidget.Height + InsertBarPosition.Y));
                var cursorRect = new RoundedRect(bar2, 0);
                graphics2D.Render(cursorRect, this.CursorColor);
            }

            RectangleDouble boundsPlusPoint5 = LocalBounds;

            boundsPlusPoint5.Inflate(-.5);
            var borderRect = new RoundedRect(boundsPlusPoint5, 0);
            var borderLine = new Stroke(borderRect);

            base.OnDraw(graphics2D);
        }
Пример #24
0
        public Task SaveSheets()
        {
            return(ApplicationController.Instance.Tasks.Execute(
                       "Export Part Sheet".Localize(),
                       null,
                       async(reporter, cancelationToken) =>
            {
                var progressStatus = new ProgressStatus();

                var processCount = 0.0;
                currentlySaving = true;
                // first create images for all the parts
                foreach (var item in itemSource)
                {
                    progressStatus.Status = item.Name;
                    reporter.Report(progressStatus);

                    var xxx = itemSource.Count();
                    var yyy = itemSource.FirstOrDefault()?.Name;

                    var object3D = await item.CreateContent();

                    var loadedMeshGroups = object3D.VisibleMeshes().ToList();
                    if (loadedMeshGroups?.Count > 0)
                    {
                        AxisAlignedBoundingBox aabb = loadedMeshGroups[0].Mesh.GetAxisAlignedBoundingBox(loadedMeshGroups[0].WorldMatrix());

                        for (int i = 1; i < loadedMeshGroups.Count; i++)
                        {
                            aabb = AxisAlignedBoundingBox.Union(aabb, loadedMeshGroups[i].Mesh.GetAxisAlignedBoundingBox(loadedMeshGroups[i].WorldMatrix()));
                        }

                        RectangleDouble bounds2D = new RectangleDouble(aabb.MinXYZ.X, aabb.MinXYZ.Y, aabb.MaxXYZ.X, aabb.MaxXYZ.Y);
                        double widthInMM = bounds2D.Width + PartMarginMM * 2;
                        double textSpaceMM = 5;
                        double heightMM = textSpaceMM + bounds2D.Height + PartMarginMM * 2;

                        TypeFacePrinter typeFacePrinter = new TypeFacePrinter(item.Name, 28, Vector2.Zero, Justification.Center, Baseline.BoundsCenter);
                        double sizeOfNameX = typeFacePrinter.GetSize().X + PartMarginPixels * 2;
                        Vector2 sizeOfRender = new Vector2(widthInMM * PixelPerMM, heightMM * PixelPerMM);

                        ImageBuffer imageOfPart = new ImageBuffer((int)(Math.Max(sizeOfNameX, sizeOfRender.X)), (int)(sizeOfRender.Y));
                        typeFacePrinter.Origin = new Vector2(imageOfPart.Width / 2, (textSpaceMM / 2) * PixelPerMM);

                        Graphics2D partGraphics2D = imageOfPart.NewGraphics2D();

                        RectangleDouble rectBounds = new RectangleDouble(0, 0, imageOfPart.Width, imageOfPart.Height);
                        double strokeWidth = .5 * PixelPerMM;
                        rectBounds.Inflate(-strokeWidth / 2);
                        RoundedRect rect = new RoundedRect(rectBounds, PartMarginMM * PixelPerMM);
                        partGraphics2D.Render(rect, Color.LightGray);
                        Stroke rectOutline = new Stroke(rect, strokeWidth);
                        partGraphics2D.Render(rectOutline, Color.DarkGray);

                        foreach (var meshGroup in loadedMeshGroups)
                        {
                            PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partGraphics2D, meshGroup.Mesh, meshGroup.WorldMatrix(), new Vector2(-bounds2D.Left + PartMarginMM, -bounds2D.Bottom + textSpaceMM + PartMarginMM), PixelPerMM, Color.Black);
                        }
                        partGraphics2D.Render(typeFacePrinter, Color.Black);

                        partImagesToPrint.Add(new PartImage(imageOfPart));
                    }

                    progressStatus.Progress0To1 = Math.Min(processCount / itemSource.Count, .95);
                    reporter.Report(progressStatus);
                    processCount++;
                }

                progressStatus.Status = "Saving".Localize();
                reporter.Report(progressStatus);

                partImagesToPrint.Sort(BiggestToLittlestImages);

                PdfDocument document = new PdfDocument();
                document.Info.Title = "MatterHackers Parts Sheet";
                document.Info.Author = "MatterHackers Inc.";
                document.Info.Subject = "This is a list of the parts that are in a queue from MatterControl.";
                document.Info.Keywords = "MatterControl, STL, 3D Printing";

                int nextPartToPrintIndex = 0;
                int plateNumber = 1;
                bool done = false;

                while (!done && nextPartToPrintIndex < partImagesToPrint.Count)
                {
                    PdfPage pdfPage = document.AddPage();
                    CreateOnePage(plateNumber++, ref nextPartToPrintIndex, pdfPage);
                }

                try
                {
                    // save the final document
                    document.Save(pathAndFileToSaveTo);

                    // Now try and open the document. This will launch whatever PDF viewer is on the system and ask it
                    // to show the file (at least on Windows).
                    Process.Start(pathAndFileToSaveTo);
                }
                catch (Exception)
                {
                }

                currentlySaving = false;

                progressStatus.Progress0To1 = 1;
                reporter.Report(progressStatus);
            }));
        }
Пример #25
0
        private void DoLayoutChildren(LayoutEventArgs layoutEventArgs)
        {
            GuiWidget parent = layoutEventArgs.ParentWidget;

            if (parent.CountVisibleChildren() == 0)
            {
                return;
            }

            RectangleDouble boundsOfAllChildrenIncludingMargin = RectangleDouble.ZeroIntersection;

            double totalWidthWithMargin  = 0;
            double totalHeightWithMargin = 0;

            double totalWidthOfStaticItems  = 0;
            double totalHeightOfStaticItems = 0;
            int    numItemsNeedingExpanding = 0;

            double totalMinimumWidthOfAllItems  = 0;
            double totalMinimumHeightOfAllItems = 0;

            for (int childIndex = 0; childIndex < parent.Children.Count; childIndex++)
            {
                GuiWidget child = parent.Children[childIndex];
                if (child.Visible == false)
                {
                    continue;
                }

                RectangleDouble childBoundsWithMargin = child.LocalBounds;
                childBoundsWithMargin.Inflate(child.Margin);
                totalWidthWithMargin  += childBoundsWithMargin.Width;
                totalHeightWithMargin += childBoundsWithMargin.Height;
                boundsOfAllChildrenIncludingMargin.ExpandToInclude(childBoundsWithMargin);

                switch (FlowDirection)
                {
                case UI.FlowDirection.LeftToRight:
                case UI.FlowDirection.RightToLeft:
                    totalMinimumWidthOfAllItems += child.MinimumSize.x + child.Margin.Width;
                    totalMinimumHeightOfAllItems = Math.Max(totalMinimumHeightOfAllItems, child.MinimumSize.y + child.Margin.Height);

                    if (child.HAnchorIsSet(HAnchor.ParentLeftRight))
                    {
                        numItemsNeedingExpanding++;
                        totalWidthOfStaticItems += child.Margin.Width;
                    }
                    else if (child.HAnchor == HAnchor.AbsolutePosition || child.HAnchorIsSet(HAnchor.FitToChildren))
                    {
                        totalWidthOfStaticItems += childBoundsWithMargin.Width;
                    }
                    else
                    {
                        throw new Exception("Only None or ParentLeftRight are valid HAnchor for a horizontal flowWidget.");
                    }
                    break;

                case UI.FlowDirection.TopToBottom:
                case UI.FlowDirection.BottomToTop:
                    totalMinimumWidthOfAllItems   = Math.Max(totalMinimumWidthOfAllItems, child.MinimumSize.x + child.Margin.Width);
                    totalMinimumHeightOfAllItems += child.MinimumSize.y + child.Margin.Height;
                    if (child.VAnchorIsSet(VAnchor.ParentBottomTop))
                    {
                        numItemsNeedingExpanding++;
                        totalHeightOfStaticItems += child.Margin.Height;
                    }
                    else if (child.VAnchor == VAnchor.AbsolutePosition || child.VAnchorIsSet(VAnchor.FitToChildren))
                    {
                        totalHeightOfStaticItems += childBoundsWithMargin.Height;
                    }
                    else
                    {
                        throw new Exception("Only None or ParentBottomTop are valid VAnchor for a vertial flowWidget.");
                    }
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            switch (FlowDirection)
            {
            case UI.FlowDirection.LeftToRight:
            {
                double curX = parent.Padding.Left;
                foreach (GuiWidget child in parent.Children)
                {
                    if (child.Visible == true)
                    {
                        double newX = curX - child.LocalBounds.Left + child.Margin.Left;
                        child.OriginRelativeParent = new Vector2(newX, child.OriginRelativeParent.y);
                        if (child.HAnchorIsSet(HAnchor.ParentLeftRight))
                        {
                            RectangleDouble curChildBounds = child.LocalBounds;
                            double          newWidth       = (parent.LocalBounds.Width - parent.Padding.Width - totalWidthOfStaticItems) / numItemsNeedingExpanding;
                            child.LocalBounds = new RectangleDouble(curChildBounds.Left, curChildBounds.Bottom,
                                                                    newWidth, curChildBounds.Top);
                        }
                        curX += child.LocalBounds.Width + child.Margin.Width;
                    }
                }
            }
            break;

            case UI.FlowDirection.RightToLeft:
            {
                double curX = parent.LocalBounds.Right - parent.Padding.Right;
                foreach (GuiWidget child in parent.Children)
                {
                    if (child.Visible == true)
                    {
                        if (child.HAnchorIsSet(HAnchor.ParentLeftRight))
                        {
                            RectangleDouble curChildBounds = child.LocalBounds;
                            double          newWidth       = (parent.LocalBounds.Width - parent.Padding.Width - totalWidthOfStaticItems) / numItemsNeedingExpanding;
                            child.LocalBounds = new RectangleDouble(curChildBounds.Left, curChildBounds.Bottom,
                                                                    newWidth, curChildBounds.Top);
                        }

                        double newX = curX - child.LocalBounds.Left - (child.LocalBounds.Width + child.Margin.Right);
                        child.OriginRelativeParent = new Vector2(newX, child.OriginRelativeParent.y);
                        curX -= (child.LocalBounds.Width + child.Margin.Width);
                    }
                }
            }
            break;

            case UI.FlowDirection.BottomToTop:
            {
                double curY = parent.Padding.Bottom;
                foreach (GuiWidget child in parent.Children)
                {
                    if (child.Visible == true)
                    {
                        double newY = curY - child.LocalBounds.Bottom + child.Margin.Bottom;
                        child.OriginRelativeParent = new Vector2(child.OriginRelativeParent.x, newY);
                        if (child.VAnchorIsSet(VAnchor.ParentBottomTop))
                        {
                            RectangleDouble curChildBounds = child.LocalBounds;
                            double          newHeight      = (parent.LocalBounds.Height - parent.Padding.Height - totalHeightOfStaticItems) / numItemsNeedingExpanding;
                            child.LocalBounds = new RectangleDouble(curChildBounds.Left, curChildBounds.Bottom,
                                                                    curChildBounds.Right, newHeight);
                        }
                        curY += child.LocalBounds.Height + child.Margin.Height;
                    }
                }
            }
            break;

            case UI.FlowDirection.TopToBottom:
            {
                double curY = parent.LocalBounds.Top - parent.Padding.Top;
                foreach (GuiWidget child in parent.Children)
                {
                    if (child.Visible == true)
                    {
                        if (child.VAnchorIsSet(VAnchor.ParentBottomTop))
                        {
                            RectangleDouble curChildBounds = child.LocalBounds;
                            double          newHeight      = (parent.LocalBounds.Height - parent.Padding.Height - totalHeightOfStaticItems) / numItemsNeedingExpanding;
                            child.LocalBounds = new RectangleDouble(curChildBounds.Left, curChildBounds.Bottom,
                                                                    curChildBounds.Right, newHeight);
                        }

                        double newY = curY - child.LocalBounds.Bottom - (child.LocalBounds.Height + child.Margin.Top);
                        child.OriginRelativeParent = new Vector2(child.OriginRelativeParent.x, newY);
                        curY -= (child.LocalBounds.Height + child.Margin.Height);
                    }
                }
            }
            break;

            default:
                throw new NotImplementedException();
            }
        }
Пример #26
0
        private int CalculateContentSizes(GuiWidget parent, ref Vector2 totalSizeWithMargin, ref Vector2 totalSizeOfStaticItems, ref Vector2 totalMinimumSizeOfAllItems)
        {
            int             numItemsNeedingExpanding           = 0;
            RectangleDouble boundsOfAllChildrenIncludingMargin = RectangleDouble.ZeroIntersection;

            foreach (GuiWidget child in parent.Children)
            {
                if (child.Visible == false)
                {
                    continue;
                }

                RectangleDouble childBoundsWithMargin = child.LocalBounds;
                childBoundsWithMargin.Inflate(child.DeviceMarginAndBorder);
                totalSizeWithMargin.X += childBoundsWithMargin.Width;
                totalSizeWithMargin.Y += childBoundsWithMargin.Height;
                boundsOfAllChildrenIncludingMargin.ExpandToInclude(childBoundsWithMargin);

                switch (FlowDirection)
                {
                case UI.FlowDirection.LeftToRight:
                case UI.FlowDirection.RightToLeft:
                    totalMinimumSizeOfAllItems.X += child.MinimumFlowSize().X + child.DeviceMarginAndBorder.Width;
                    totalMinimumSizeOfAllItems.Y  = Math.Max(totalMinimumSizeOfAllItems.Y, child.MinimumFlowSize().Y + child.DeviceMarginAndBorder.Height);

                    if (child.HAnchorIsSet(HAnchor.Stretch))
                    {
                        numItemsNeedingExpanding++;
                        totalSizeOfStaticItems.X += child.DeviceMarginAndBorder.Width;
                    }
                    else if (child.HAnchor == HAnchor.Absolute ||
                             child.HAnchorIsSet(HAnchor.Fit) ||
                             child.HAnchorIsSet(HAnchor.MinFitOrStretch))
                    {
                        totalSizeOfStaticItems.X += childBoundsWithMargin.Width;
                    }
                    else
                    {
                        throw new Exception("Only Absolute or Stretch are valid HAnchor for a horizontal flowWidget.");
                    }

                    break;

                case UI.FlowDirection.TopToBottom:
                case UI.FlowDirection.BottomToTop:
                    totalMinimumSizeOfAllItems.X  = Math.Max(totalMinimumSizeOfAllItems.X, child.MinimumFlowSize().X + child.DeviceMarginAndBorder.Width);
                    totalMinimumSizeOfAllItems.Y += child.MinimumFlowSize().Y + child.DeviceMarginAndBorder.Height;
                    if (child.VAnchorIsSet(VAnchor.Stretch))
                    {
                        numItemsNeedingExpanding++;
                        totalSizeOfStaticItems.Y += child.DeviceMarginAndBorder.Height;
                    }
                    else if (child.VAnchor == VAnchor.Absolute || child.VAnchorIsSet(VAnchor.Fit))
                    {
                        totalSizeOfStaticItems.Y += childBoundsWithMargin.Height;
                    }
                    else
                    {
                        throw new Exception("Only Absolute or Stretch are valid VAnchor for a vertical flowWidget.");
                    }

                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            return(numItemsNeedingExpanding);
        }
Пример #27
0
        private void DoLayoutChildren(LayoutEventArgs layoutEventArgs)
        {
            GuiWidget parent = layoutEventArgs.ParentWidget;

            if (parent.CountVisibleChildren() == 0)
            {
                return;
            }

            RectangleDouble boundsOfAllChildrenIncludingMargin = RectangleDouble.ZeroIntersection;
            var             totalSizeWithMargin        = Vector2.Zero;
            var             totalSizeOfStaticItems     = Vector2.Zero;
            var             totalMinimumSizeOfAllItems = Vector2.Zero;

            double totalWidthWithMargin  = 0;
            double totalHeightWithMargin = 0;

            foreach (GuiWidget child in parent.Children)
            {
                if (parent.HasBeenClosed)
                {
                    return;
                }

                if (child.Visible == false)
                {
                    continue;
                }

                RectangleDouble childBoundsWithMargin = child.LocalBounds;
                childBoundsWithMargin.Inflate(child.DeviceMarginAndBorder);
                totalWidthWithMargin  += childBoundsWithMargin.Width;
                totalHeightWithMargin += childBoundsWithMargin.Height;
                boundsOfAllChildrenIncludingMargin.ExpandToInclude(childBoundsWithMargin);
            }

            int numItemsNeedingExpanding = CalculateContentSizes(parent,
                                                                 ref totalSizeWithMargin,
                                                                 ref totalSizeOfStaticItems,
                                                                 ref totalMinimumSizeOfAllItems);

            switch (FlowDirection)
            {
            case UI.FlowDirection.LeftToRight:
            {
                double curX = parent.DevicePadding.Left;
                foreach (GuiWidget child in parent.Children)
                {
                    if (parent.HasBeenClosed)
                    {
                        return;
                    }

                    if (child.Visible == true)
                    {
                        double newX = curX - child.LocalBounds.Left + child.DeviceMarginAndBorder.Left;
                        child.OriginRelativeParent = new Vector2(newX, child.OriginRelativeParent.Y);
                        if (child.HAnchorIsSet(HAnchor.Stretch))
                        {
                            RectangleDouble curChildBounds = child.LocalBounds;
                            double          newWidth       = (parent.LocalBounds.Width - parent.DevicePadding.Width - totalSizeOfStaticItems.X) / numItemsNeedingExpanding;
                            child.LocalBounds = new RectangleDouble(curChildBounds.Left,
                                                                    curChildBounds.Bottom,
                                                                    curChildBounds.Left + newWidth,
                                                                    curChildBounds.Top);
                        }

                        curX += child.LocalBounds.Width + child.DeviceMarginAndBorder.Width;
                    }
                }
            }

            break;

            case UI.FlowDirection.RightToLeft:
            {
                double curX = parent.LocalBounds.Right - parent.DevicePadding.Right;
                foreach (GuiWidget child in parent.Children)
                {
                    if (parent.HasBeenClosed)
                    {
                        return;
                    }

                    if (child.Visible == true)
                    {
                        if (child.HAnchorIsSet(HAnchor.Stretch))
                        {
                            RectangleDouble curChildBounds = child.LocalBounds;
                            double          newWidth       = (parent.LocalBounds.Width - parent.DevicePadding.Width - totalSizeOfStaticItems.X) / numItemsNeedingExpanding;
                            child.LocalBounds = new RectangleDouble(curChildBounds.Left,
                                                                    curChildBounds.Bottom,
                                                                    curChildBounds.Left + newWidth,
                                                                    curChildBounds.Top);
                        }

                        double newX = curX - child.LocalBounds.Left - (child.LocalBounds.Width + child.DeviceMarginAndBorder.Right);
                        child.OriginRelativeParent = new Vector2(newX, child.OriginRelativeParent.Y);
                        curX -= child.LocalBounds.Width + child.DeviceMarginAndBorder.Width;
                    }
                }
            }

            break;

            case UI.FlowDirection.BottomToTop:
            {
                double curY = parent.DevicePadding.Bottom;
                foreach (GuiWidget child in parent.Children)
                {
                    if (parent.HasBeenClosed)
                    {
                        return;
                    }

                    if (child.Visible == true)
                    {
                        double newY = curY - child.LocalBounds.Bottom + child.DeviceMarginAndBorder.Bottom;
                        child.OriginRelativeParent = new Vector2(child.OriginRelativeParent.X, newY);
                        if (child.VAnchorIsSet(VAnchor.Stretch))
                        {
                            RectangleDouble curChildBounds = child.LocalBounds;
                            double          newHeight      = (parent.LocalBounds.Height - parent.DevicePadding.Height - totalSizeOfStaticItems.Y) / numItemsNeedingExpanding;
                            child.LocalBounds = new RectangleDouble(curChildBounds.Left,
                                                                    curChildBounds.Bottom,
                                                                    curChildBounds.Right,
                                                                    curChildBounds.Bottom + newHeight);
                        }

                        curY += child.LocalBounds.Height + child.DeviceMarginAndBorder.Height;
                    }
                }
            }

            break;

            case UI.FlowDirection.TopToBottom:
            {
                double curY = parent.LocalBounds.Top - parent.DevicePadding.Top;
                foreach (GuiWidget child in parent.Children)
                {
                    if (parent.HasBeenClosed)
                    {
                        return;
                    }

                    if (child.Visible == true)
                    {
                        if (child.VAnchorIsSet(VAnchor.Stretch))
                        {
                            RectangleDouble curChildBounds = child.LocalBounds;
                            double          newHeight      = (parent.LocalBounds.Height - parent.DevicePadding.Height - totalSizeOfStaticItems.Y) / numItemsNeedingExpanding;                                                                       // - child.DeviceMarginAndBorder.Height;
                            child.LocalBounds = new RectangleDouble(curChildBounds.Left,
                                                                    curChildBounds.Bottom,
                                                                    curChildBounds.Right,
                                                                    curChildBounds.Bottom + newHeight);
                        }

                        double newY = curY - child.LocalBounds.Bottom - (child.LocalBounds.Height + child.DeviceMarginAndBorder.Top);
                        child.OriginRelativeParent = new Vector2(child.OriginRelativeParent.X, newY);
                        curY -= child.LocalBounds.Height + child.DeviceMarginAndBorder.Height;
                    }
                }
            }

            break;

            default:
                throw new NotImplementedException();
            }
        }
Пример #28
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			CheckBox checkBox = (CheckBox)Parent;

			double bottom = 0;

			// the check
			if (checkBox.Checked)
			{
				graphics2D.Line(new Vector2(1, CheckBoxWidth + bottom), new Vector2(1 + CheckBoxWidth, 0 + bottom), this.TextColor);
				graphics2D.Line(new Vector2(1, 0 + bottom), new Vector2(1 + CheckBoxWidth, CheckBoxWidth + bottom), this.TextColor);
			}

			// the frame
			RectangleDouble clampedRect = new RectangleDouble(1, Math.Floor(0 + bottom), 1 + Math.Ceiling(CheckBoxWidth), Math.Ceiling(CheckBoxWidth + bottom));
			graphics2D.Rectangle(clampedRect, this.TextColor);

			// extra frame
			if (checkBox.MouseDownOnButton && checkBox.FirstWidgetUnderMouse)
			{
				clampedRect.Inflate(1);
				graphics2D.Rectangle(clampedRect, this.TextColor);
			}

			base.OnDraw(graphics2D);
		}
Пример #29
0
        private void DoLayoutChildren(LayoutEventArgs layoutEventArgs)
        {
            GuiWidget parent = layoutEventArgs.ParentWidget;

            if (parent.CountVisibleChildren() == 0)
            {
                return;
            }

            RectangleDouble boundsOfAllChildrenIncludingMargin = RectangleDouble.ZeroIntersection;
            var             totalSizeWithMargin        = Vector2.Zero;
            var             totalSizeOfStaticItems     = Vector2.Zero;
            var             totalMinimumSizeOfAllItems = Vector2.Zero;

            double totalWidthWithMargin  = 0;
            double totalHeightWithMargin = 0;

            foreach (GuiWidget child in parent.Children)
            {
                if (parent.HasBeenClosed)
                {
                    return;
                }

                if (child.Visible == false)
                {
                    continue;
                }

                RectangleDouble childBoundsWithMargin = child.LocalBounds;
                childBoundsWithMargin.Inflate(child.DeviceMarginAndBorder);
                totalWidthWithMargin  += childBoundsWithMargin.Width;
                totalHeightWithMargin += childBoundsWithMargin.Height;
                boundsOfAllChildrenIncludingMargin.ExpandToInclude(childBoundsWithMargin);
            }

            int numItemsNeedingExpanding = CalculateContentSizes(parent,
                                                                 ref totalSizeWithMargin,
                                                                 ref totalSizeOfStaticItems,
                                                                 ref totalMinimumSizeOfAllItems);

            var availableSpaceInParent = new Vector2(parent.LocalBounds.Width - parent.DevicePadding.Width,
                                                     parent.LocalBounds.Height - parent.DevicePadding.Height);
            var sizePerChild = new Vector2((availableSpaceInParent.X - totalSizeOfStaticItems.X) / numItemsNeedingExpanding,
                                           (availableSpaceInParent.Y - totalSizeOfStaticItems.Y) / numItemsNeedingExpanding);

            if (numItemsNeedingExpanding > 0)
            {
                // Iterate all the children and add back in and size that they can't grow bigger than back into the sizePerChild.
                var extraSizeDueToMax = default(Vector2);
                var maxSizeCount      = default(Point2D);

                foreach (GuiWidget child in parent.Children)
                {
                    if (child.MaximumSize.X < sizePerChild.X)
                    {
                        extraSizeDueToMax.X += sizePerChild.X - child.MaximumSize.X;
                        maxSizeCount.x++;
                    }

                    if (child.MaximumSize.Y < sizePerChild.Y)
                    {
                        extraSizeDueToMax.Y += sizePerChild.Y - child.MaximumSize.Y;
                        maxSizeCount.y++;
                    }
                }

                // add back in the amount this item cannot grow to the amount we will try to give each child
                if (maxSizeCount.x > 0)
                {
                    sizePerChild.X += extraSizeDueToMax.X / (numItemsNeedingExpanding - maxSizeCount.x);
                }

                if (maxSizeCount.y > 0)
                {
                    sizePerChild.Y += extraSizeDueToMax.Y / (numItemsNeedingExpanding - maxSizeCount.y);
                }
            }

            switch (FlowDirection)
            {
            case UI.FlowDirection.LeftToRight:
            {
                double curX = parent.DevicePadding.Left;
                foreach (GuiWidget child in parent.Children)
                {
                    if (parent.HasBeenClosed)
                    {
                        return;
                    }

                    if (child.Visible == true)
                    {
                        double newX = curX - child.LocalBounds.Left + child.DeviceMarginAndBorder.Left;
                        child.OriginRelativeParent = new Vector2(newX, child.OriginRelativeParent.Y);
                        if (child.HAnchorIsSet(HAnchor.Stretch))
                        {
                            RectangleDouble curChildBounds = child.LocalBounds;
                            child.LocalBounds = new RectangleDouble(curChildBounds.Left,
                                                                    curChildBounds.Bottom,
                                                                    curChildBounds.Left + sizePerChild.X,
                                                                    curChildBounds.Top);
                        }

                        curX += child.LocalBounds.Width + child.DeviceMarginAndBorder.Width;
                    }
                }
            }

            break;

            case UI.FlowDirection.RightToLeft:
            {
                double curX = parent.LocalBounds.Right - parent.DevicePadding.Right;
                foreach (GuiWidget child in parent.Children)
                {
                    if (parent.HasBeenClosed)
                    {
                        return;
                    }

                    if (child.Visible == true)
                    {
                        if (child.HAnchorIsSet(HAnchor.Stretch))
                        {
                            RectangleDouble curChildBounds = child.LocalBounds;
                            child.LocalBounds = new RectangleDouble(curChildBounds.Left,
                                                                    curChildBounds.Bottom,
                                                                    curChildBounds.Left + sizePerChild.X,
                                                                    curChildBounds.Top);
                        }

                        double newX = curX - child.LocalBounds.Left - (child.LocalBounds.Width + child.DeviceMarginAndBorder.Right);
                        child.OriginRelativeParent = new Vector2(newX, child.OriginRelativeParent.Y);
                        curX -= child.LocalBounds.Width + child.DeviceMarginAndBorder.Width;
                    }
                }
            }

            break;

            case UI.FlowDirection.BottomToTop:
            {
                double curY = parent.DevicePadding.Bottom;
                foreach (GuiWidget child in parent.Children)
                {
                    if (parent.HasBeenClosed)
                    {
                        return;
                    }

                    if (child.Visible == true)
                    {
                        double newY = curY - child.LocalBounds.Bottom + child.DeviceMarginAndBorder.Bottom;
                        child.OriginRelativeParent = new Vector2(child.OriginRelativeParent.X, newY);
                        if (child.VAnchorIsSet(VAnchor.Stretch))
                        {
                            RectangleDouble curChildBounds = child.LocalBounds;
                            child.LocalBounds = new RectangleDouble(curChildBounds.Left,
                                                                    curChildBounds.Bottom,
                                                                    curChildBounds.Right,
                                                                    curChildBounds.Bottom + sizePerChild.Y);
                        }

                        curY += child.LocalBounds.Height + child.DeviceMarginAndBorder.Height;
                    }
                }
            }

            break;

            case UI.FlowDirection.TopToBottom:
            {
                double curY = parent.LocalBounds.Top - parent.DevicePadding.Top;
                foreach (GuiWidget child in parent.Children)
                {
                    if (parent.HasBeenClosed)
                    {
                        return;
                    }

                    if (child.Visible == true)
                    {
                        if (child.VAnchorIsSet(VAnchor.Stretch))
                        {
                            RectangleDouble curChildBounds = child.LocalBounds;
                            child.LocalBounds = new RectangleDouble(curChildBounds.Left,
                                                                    curChildBounds.Bottom,
                                                                    curChildBounds.Right,
                                                                    curChildBounds.Bottom + sizePerChild.Y);
                        }

                        double newY = curY - child.LocalBounds.Bottom - (child.LocalBounds.Height + child.DeviceMarginAndBorder.Top);
                        child.OriginRelativeParent = new Vector2(child.OriginRelativeParent.X, newY);
                        curY -= child.LocalBounds.Height + child.DeviceMarginAndBorder.Height;
                    }
                }
            }

            break;

            default:
                throw new NotImplementedException();
            }
        }
Пример #30
0
        public void SavingFunction()
        {
            currentlySaving        = true;
            countThatHaveBeenSaved = 0;
            // first create images for all the parts
            foreach (string stlFileName in stlFilesToPrint)
            {
                Mesh loadedMesh = StlProcessing.Load(stlFileName);
                if (loadedMesh != null)
                {
                    AxisAlignedBoundingBox aabb     = loadedMesh.GetAxisAlignedBoundingBox();
                    RectangleDouble        bounds2D = new RectangleDouble(aabb.minXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.x, aabb.maxXYZ.y);
                    double widthInMM   = bounds2D.Width + PartMarginMM * 2;
                    double textSpaceMM = 5;
                    double heightMM    = textSpaceMM + bounds2D.Height + PartMarginMM * 2;

                    string          partName        = System.IO.Path.GetFileName(System.IO.Path.GetFileName(stlFileName));
                    TypeFacePrinter typeFacePrinter = new TypeFacePrinter(partName, 28, Vector2.Zero, Justification.Center, Baseline.BoundsCenter);
                    double          sizeOfNameX     = typeFacePrinter.GetSize().x + PartMarginPixels * 2;
                    Vector2         sizeOfRender    = new Vector2(widthInMM * PixelPerMM, heightMM * PixelPerMM);

                    ImageBuffer imageOfPart = new ImageBuffer((int)(Math.Max(sizeOfNameX, sizeOfRender.x)), (int)(sizeOfRender.y), 32, new BlenderBGRA());
                    typeFacePrinter.Origin = new Vector2(imageOfPart.Width / 2, (textSpaceMM / 2) * PixelPerMM);

                    Graphics2D partGraphics2D = imageOfPart.NewGraphics2D();

                    RectangleDouble rectBounds  = new RectangleDouble(0, 0, imageOfPart.Width, imageOfPart.Height);
                    double          strokeWidth = .5 * PixelPerMM;
                    rectBounds.Inflate(-strokeWidth / 2);
                    RoundedRect rect = new RoundedRect(rectBounds, PartMarginMM * PixelPerMM);
                    partGraphics2D.Render(rect, RGBA_Bytes.LightGray);
                    Stroke rectOutline = new Stroke(rect, strokeWidth);
                    partGraphics2D.Render(rectOutline, RGBA_Bytes.DarkGray);

                    PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partGraphics2D, loadedMesh, new Vector2(-bounds2D.Left + PartMarginMM, -bounds2D.Bottom + textSpaceMM + PartMarginMM), PixelPerMM, RGBA_Bytes.Black);
                    partGraphics2D.Render(typeFacePrinter, RGBA_Bytes.Black);

                    partImagesToPrint.Add(new PartImage(imageOfPart));
                }
                countThatHaveBeenSaved++;
                if (UpdateRemainingItems != null)
                {
                    UpdateRemainingItems(this, new StringEventArgs(Path.GetFileName(stlFileName)));
                }
            }

            partImagesToPrint.Sort(BiggestToLittlestImages);

            PdfDocument document = new PdfDocument();

            document.Info.Title    = "MatterHackers Parts Sheet";
            document.Info.Author   = "MatterHackers Inc.";
            document.Info.Subject  = "This is a list of the parts that are in a queue from MatterControl.";
            document.Info.Keywords = "MatterControl, STL, 3D Printing";

            int  nextPartToPrintIndex = 0;
            int  plateNumber          = 1;
            bool done = false;

            while (!done && nextPartToPrintIndex < partImagesToPrint.Count)
            {
                PdfPage pdfPage = document.AddPage();
                CreateOnePage(plateNumber++, ref nextPartToPrintIndex, pdfPage);
            }
            try
            {
                document.Save(pathAndFileToSaveTo);
                Process.Start(pathAndFileToSaveTo);
            }
            catch {
            }

            OnDoneSaving();
            currentlySaving = false;
        }
Пример #31
0
        public void SavingFunction()
        {
            currentlySaving        = true;
            countThatHaveBeenSaved = 0;
            // first create images for all the parts
            foreach (FileNameAndPresentationName queuePartFileName in queuPartFilesToAdd)
            {
                List <MeshGroup> loadedMeshGroups = null;
                if (File.Exists(queuePartFileName.fileName))
                {
                    loadedMeshGroups = MeshFileIo.Load(queuePartFileName.fileName);
                }

                if (loadedMeshGroups != null)
                {
                    bool firstMeshGroup         = true;
                    AxisAlignedBoundingBox aabb = null;
                    foreach (MeshGroup meshGroup in loadedMeshGroups)
                    {
                        if (firstMeshGroup)
                        {
                            aabb           = meshGroup.GetAxisAlignedBoundingBox();
                            firstMeshGroup = false;
                        }
                        else
                        {
                            aabb = AxisAlignedBoundingBox.Union(aabb, meshGroup.GetAxisAlignedBoundingBox());
                        }
                    }
                    RectangleDouble bounds2D    = new RectangleDouble(aabb.minXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.x, aabb.maxXYZ.y);
                    double          widthInMM   = bounds2D.Width + PartMarginMM * 2;
                    double          textSpaceMM = 5;
                    double          heightMM    = textSpaceMM + bounds2D.Height + PartMarginMM * 2;

                    TypeFacePrinter typeFacePrinter = new TypeFacePrinter(queuePartFileName.presentationName, 28, Vector2.Zero, Justification.Center, Baseline.BoundsCenter);
                    double          sizeOfNameX     = typeFacePrinter.GetSize().x + PartMarginPixels * 2;
                    Vector2         sizeOfRender    = new Vector2(widthInMM * PixelPerMM, heightMM * PixelPerMM);

                    ImageBuffer imageOfPart = new ImageBuffer((int)(Math.Max(sizeOfNameX, sizeOfRender.x)), (int)(sizeOfRender.y), 32, new BlenderBGRA());
                    typeFacePrinter.Origin = new Vector2(imageOfPart.Width / 2, (textSpaceMM / 2) * PixelPerMM);

                    Graphics2D partGraphics2D = imageOfPart.NewGraphics2D();

                    RectangleDouble rectBounds  = new RectangleDouble(0, 0, imageOfPart.Width, imageOfPart.Height);
                    double          strokeWidth = .5 * PixelPerMM;
                    rectBounds.Inflate(-strokeWidth / 2);
                    RoundedRect rect = new RoundedRect(rectBounds, PartMarginMM * PixelPerMM);
                    partGraphics2D.Render(rect, RGBA_Bytes.LightGray);
                    Stroke rectOutline = new Stroke(rect, strokeWidth);
                    partGraphics2D.Render(rectOutline, RGBA_Bytes.DarkGray);

                    foreach (MeshGroup meshGroup in loadedMeshGroups)
                    {
                        foreach (Mesh loadedMesh in meshGroup.Meshes)
                        {
                            PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partGraphics2D, loadedMesh, new Vector2(-bounds2D.Left + PartMarginMM, -bounds2D.Bottom + textSpaceMM + PartMarginMM), PixelPerMM, RGBA_Bytes.Black);
                        }
                    }
                    partGraphics2D.Render(typeFacePrinter, RGBA_Bytes.Black);

                    partImagesToPrint.Add(new PartImage(imageOfPart));

                    countThatHaveBeenSaved++;
                }

                if (UpdateRemainingItems != null)
                {
                    UpdateRemainingItems(this, new StringEventArgs(Path.GetFileName(queuePartFileName.presentationName)));
                }
            }

            partImagesToPrint.Sort(BiggestToLittlestImages);

            PdfDocument document = new PdfDocument();

            document.Info.Title    = "MatterHackers Parts Sheet";
            document.Info.Author   = "MatterHackers Inc.";
            document.Info.Subject  = "This is a list of the parts that are in a queue from MatterControl.";
            document.Info.Keywords = "MatterControl, STL, 3D Printing";

            int  nextPartToPrintIndex = 0;
            int  plateNumber          = 1;
            bool done = false;

            while (!done && nextPartToPrintIndex < partImagesToPrint.Count)
            {
                PdfPage pdfPage = document.AddPage();
                CreateOnePage(plateNumber++, ref nextPartToPrintIndex, pdfPage);
            }
            try
            {
                // save the final document
                document.Save(pathAndFileToSaveTo);
                // Now try and open the document. This will lanch whatever PDF viewer is on the system and ask it
                // to show the file (at least on Windows).
                Process.Start(pathAndFileToSaveTo);
            }
            catch (Exception)
            {
            }

            OnDoneSaving();
            currentlySaving = false;
        }