コード例 #1
0
        public static void AddImage(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            string directory   = Path.GetDirectoryName(path);
            string file        = Path.GetFileName(path);
            string absoluteDir = HttpContext.Current.Server.MapPath(directory);

            string[] filePaths = Directory.GetFiles(absoluteDir, file);

            if (SpriteSettings == null)
            {
                SpriteSettings = new LayoutProperties
                {
                    distanceBetweenImages = 0,
                    inputFilePaths        = filePaths,
                    outputCssFilePath     = HttpContext.Current.Server.MapPath("~/autosprite.css"),
                    outputSpriteFilePath  = HttpContext.Current.Server.MapPath("~/autosprite.png"),
                    layout = "Automatic"
                };
            }
            else
            {
                List <string> inputFilePaths = SpriteSettings.inputFilePaths.ToList();
                inputFilePaths.AddRange(filePaths);
                SpriteSettings.inputFilePaths = inputFilePaths.ToArray();
            }
        }
コード例 #2
0
        public bool Create(string fileName, string layoutName, LayoutType layoutType)
        {
            m_FileName = fileName;
            m_Layout   = new Layout();

            FrontSideLayout = new LayoutProperties()
            {
                Name            = layoutName,
                LayoutType      = layoutType,
                Size            = new System.Windows.Point(21, 14.8),
                BackgroundImage = LayoutFileReader.ImageToByte(Properties.Resources.DefaultBackground)
            };

            RearSideLayout = new LayoutProperties()
            {
                Name            = layoutName,
                LayoutType      = layoutType,
                Size            = new System.Windows.Point(21, 14.8),
                BackgroundImage = LayoutFileReader.ImageToByte(Properties.Resources.DefaultBackground)
            };

            try
            {
                Save();

                return(true);
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.TraceError(e.ToString());
                LastException = e;
            }

            return(false);
        }
コード例 #3
0
        private string SerializeToString(LayoutProperties prop)
        {
            if (prop == null)
            {
                throw new InvalidOperationException();
            }

            prop.Check();

            var xml = "";

            using (var writer = new StringWriter())
            {
                try
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(LayoutProperties));
                    serializer.Serialize(writer, prop);
                    xml = writer.GetStringBuilder().ToString();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "SupplementLayout.SerializeToString()", MessageBoxButton.OK);
                }
            }
            return(xml);
        }
コード例 #4
0
        public void LoadLayout(LayoutProperties prop)
        {
            using (new WaitCursor())
            {
                if (prop != null)
                {
                    var mediaOffset = prop.OffsetInPixel;

                    ClearLayout();

                    ImageBackground.Stretch = Stretch.Fill;
                    ImageBackground.Source  = LayoutFileReader.ByteToImageSource(prop.BackgroundImage);
                    Canvas.SetLeft(ImageBackground, mediaOffset.X);
                    Canvas.SetTop(ImageBackground, mediaOffset.Y);

                    foreach (var ci in prop.m_CaptionInfo)
                    {
                        AddSpanElement(ci, mediaOffset);
                    }
                    foreach (var ci in prop.m_Table)
                    {
                        AddTableElement(ci, mediaOffset);
                    }
                    foreach (var ci in prop.m_GuideLineInfo)
                    {
                        AddGuigeLine(ci, mediaOffset);
                    }
                    foreach (var ci in prop.m_ZSumbolInfo)
                    {
                        AddZSumbolElement(ci, mediaOffset);
                    }
                }
            }
        }
コード例 #5
0
ファイル: MudTheme.cs プロジェクト: zHaytam/MudBlazor
 public MudTheme()
 {
     Palette          = new Palette();
     LayoutProperties = new LayoutProperties();
     Shadows          = new Shadow();
     ZIndex           = new ZIndex();
 }
コード例 #6
0
        public void LoadLayout(LayoutProperties prop)
        {
            LayoutProperties = prop;
            using (new WaitCursor())
            {
                if (prop != null)
                {
                    ClearLayout();

                    foreach (var ci in prop.m_AudioPlayerInfo)
                    {
                        AddAudioPlaybackControl(ci);
                    }

                    foreach (var ci in prop.m_VideoPlayerInfo)
                    {
                        AddVideoPlaybackControl(ci);
                    }

                    foreach (var ci in prop.m_PowerPointInfo)
                    {
                        AddPowerPointControl(ci);
                    }
                }
            }
            OnDeskLayoutLoaded(this, new DeskLayoutEventArgs(null)
            {
                UIElementEventType = UIElementEventType.Loaded
            });
        }
コード例 #7
0
ファイル: MudTheme.cs プロジェクト: weiplanet/MudBlazor
 public MudTheme()
 {
     Palette          = new Palette();
     PaletteDark      = Palette.ConvertToDarkTheme(new Palette());
     Shadows          = new Shadow();
     Typography       = new Typography();
     LayoutProperties = new LayoutProperties();
     ZIndex           = new ZIndex();
 }
コード例 #8
0
        private void SaveSettings()
        {
            GrepSettings.Instance.Set(GrepSettings.Key.ReplaceWindowWrap, cbWrapText.IsChecked);
            GrepSettings.Instance.Set(GrepSettings.Key.ReplaceWindowFontSize, (int)zoomSlider.Value);

            LayoutProperties.ReplaceBounds = new Rect(
                Left,
                Top,
                ActualWidth,
                ActualHeight);
            LayoutProperties.Save();
        }
コード例 #9
0
ファイル: Layout.cs プロジェクト: cdiggins/widgetology
 // Constructor
 public Layout(
     Func <Rect, int, int, Rect> strategy,
     LayoutProperties props            = null,
     Style style                       = null,
     IReadOnlyList <IControl> controls = null) :
     base(OnKeyPress,
          OnMouse,
          OnPaint)
 {
     Props    = props ?? LayoutProperties.Default;
     Strategy = strategy;
     Style    = style ?? new Style();
     Controls = controls ?? Array.Empty <ILayout>();
 }
コード例 #10
0
        private void RefreshLayoutProperties()
        {
            LayoutProperties layoutProperties = new LayoutProperties();

            layoutProperties.ControlMouseDownLocation = controlMouseDownLocation;
            layoutProperties.ControlMouseMoveLocation = controlMouseMoveLocation;
            layoutProperties.DesignAreaLocation       = DesignAreaLocation;
            layoutProperties.DesignAreaSize           = DesignAreaSize;
            layoutProperties.ViewportLocation         = ViewportLocation;
            layoutProperties.ViewportSize             = ViewportSize;
            layoutProperties.ZoomRatio = ZoomRatio;
            layoutProperties.DesignAreaMouseDownLocation = DesignAreaMouseDownLocation;
            layoutProperties.DesignAreaMouseMoveLocation = DesignAreaMouseMoveLocation;
            layoutProperties.SelectedElementLocation     = SelectedElement != null ? SelectedElement.Location : Point.Empty;
            layoutProperties.SelectedElementSize         = SelectedElement != null ? SelectedElement.Size : Size.Empty;

            propertyGrid.SelectedObject = layoutProperties;
        }
コード例 #11
0
ファイル: AtlasImporter.cs プロジェクト: Milstein/GameStack
        public override void Import(string input, Stream output)
        {
            var           ser      = new JsonSerializer();
            AtlasMetadata metadata = null;

            string metaPath = "atlas.meta";

            if (File.Exists(metaPath))
            {
                using (var sr = new StreamReader(metaPath)) {
                    metadata = ser.Deserialize <AtlasMetadata>(new JsonTextReader(sr));
                }
            }
            else
            {
                metadata = new AtlasMetadata();
            }

            var lp = new LayoutProperties {
                inputFilePaths = (Directory.Exists("./sprites") ? Directory.GetFiles("./sprites") : Directory.GetFiles("."))
                                 .Where(p => SupportedFormats.Contains(Path.GetExtension(p).ToLower())).ToArray(),
                distanceBetweenImages = metadata.Padding,
                marginWidth           = metadata.Margin,
                powerOfTwo            = metadata.PowerOfTwo,
                maxSpriteWidth        = metadata.MaxSpriteWidth > 0 ? metadata.MaxSpriteWidth : 16384,
                maxSpriteHeight       = metadata.MaxSpriteHeight > 0 ? metadata.MaxSpriteHeight : 16384,
                filterMode            = metadata.FilterMode,
            };
            var sheetMaker = new AtlasBuilder(lp);

            using (var tw = new TarWriter(output)) {
                using (MemoryStream atlasStream = new MemoryStream(), sheetStream = new MemoryStream()) {
                    using (var bw = new BinaryWriter(atlasStream)) {
                        sheetMaker.Create(bw, sheetStream, ImageFormat.Png, metadata.NoPreMultiply);
                        bw.Flush();
                        atlasStream.Position = 0;
                        sheetStream.Position = 0;
                        tw.Write(atlasStream, atlasStream.Length, "atlas.bin");
                        tw.Write(sheetStream, sheetStream.Length, "sheet.png");
                    }
                }
            }
        }
コード例 #12
0
        public DarkTheme()
        {
            Palette = new CustomPalette
            {
                Primary               = PRIMARY,
                PrimaryContrastText   = "#FFFFFF",
                Secondary             = PRIMARY,
                SecondaryContrastText = "#FFFFFF",
                AppbarBackground      = BACKGROUND_DARK,
                Tertiary              = TEXT,

                Footer     = BACKGROUND_DARK,
                FooterDark = BACKGROUND_DARKEST,
                FooterText = TEXT,

                Black                    = BACKGROUND_DEFAULT,
                Background               = BACKGROUND_LIGHT,
                BackgroundGrey           = BACKGROUND_LIGHT,
                Surface                  = BACKGROUND_DEFAULT,
                DrawerBackground         = BACKGROUND_DARK,
                DrawerText               = TEXT,
                DrawerIcon               = "rgba(255,255,255, 0.50)",
                AppbarText               = TEXT,
                TextPrimary              = TEXT,
                TextSecondary            = TEXT,
                ActionDefault            = "#adadb1",
                ActionDisabled           = "rgba(255,255,255, 0.26)",
                ActionDisabledBackground = "rgba(255,255,255, 0.12)",
                Divider                  = "rgba(255,255,255, 0.12)",
                DividerLight             = "rgba(255,255,255, 0.12)",
                TableLines               = "rgba(255,255,255, 0.12)",
                TableHover               = "rgba(255,255,255, 0.03)",
                TableStriped             = "rgba(255,255,255, 0.06)",
                LinesDefault             = "rgba(255,255,255, 0.12)",
                LinesInputs              = "rgba(255,255,255, 0.3)",
                TextDisabled             = "rgba(255,255,255, 0.2)"
            };

            LayoutProperties = new LayoutProperties
            {
                DrawerWidthLeft = "260px"
            };
        }
コード例 #13
0
        private void DrawElements(Graphics graphics)
        {
            LayoutProperties layoutProperties = new LayoutProperties();

            layoutProperties.DesignAreaLocation = DesignAreaLocation;
            layoutProperties.DesignAreaSize     = DesignAreaSize;
            layoutProperties.ViewportLocation   = ViewportLocation;
            layoutProperties.ViewportSize       = ViewportSize;
            layoutProperties.ZoomRatio          = ZoomRatio;

            foreach (LayoutElement element in Layout.Elements)
            {
                LayoutElementRenderer elementRenderer = GetElementRendererForElementType(element.TypeName);
                if (elementRenderer != null)
                {
                    elementRenderer.Draw(element, graphics, layoutProperties);

                    if (IsElementInSelection(element))
                    {
                        TransformHandleType transformHandleType = TransformHandleType.All;
                        VisualLayoutElement visualLayoutElement = element as VisualLayoutElement;
                        if (visualLayoutElement != null && !visualLayoutElement.Rotatable)
                        {
                            if (!KeyboardHelper.IsShiftKeyPressed)
                            {
                                transformHandleType = TransformHandleType.All;
                            }
                            else
                            {
                                transformHandleType = TransformHandleType.OnlyCorners;
                            }
                        }

                        DesignerHelper.DrawTransformHandles(graphics, element, layoutProperties, transformHandleType);
                    }
                }
                else
                {
                    throw new Exception("Element renderer for element type not found!");
                }
            }
        }
コード例 #14
0
        public LayoutProperties ReadLayoutXml(string xml)
        {
            LayoutProperties layoutProperties = null;

            using (var reader = new StringReader(xml))
            {
                try
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(LayoutProperties));
                    layoutProperties = (LayoutProperties)serializer.Deserialize(reader);
                }
                catch (Exception ex)
                {
                    LastException = ex;
                    MessageBox.Show(ex.ToString(), ex.Message, MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            return(layoutProperties);
        }
コード例 #15
0
        void SaveLayout(LayoutProperties prop)
        {
            using (new WaitCursor())
            {
                prop.Name = CurrentLayoutName;
                //prop.ConfigFile = LayoutConfigFile;

                prop.Offset = MainWindow.instance.Vector2DLayoutOffset.ToPoint();
                prop.Size   = MainWindow.instance.Vector2DLayoutSize.ToPoint();

                prop.m_CaptionInfo   = new List <CaptionInfo>();
                prop.m_Table         = new List <TableInfo>();
                prop.m_GuideLineInfo = new List <GuideLineInfo>();

                prop.m_CaptionInfo.AddRange(CaptionInfo.Convert(myCanvas.Children.OfType <TextSpan>().ToArray(), prop.OffsetInPixel));
                prop.m_Table.AddRange(TableInfo.Convert(myCanvas.Children.OfType <Table>().ToArray(), prop.OffsetInPixel));
                prop.m_GuideLineInfo.AddRange(GuideLineInfo.Convert(myCanvas.Children.OfType <GuideLine>().ToArray(), prop.OffsetInPixel));

                m_SupplementLayout.Save();
            }
        }
コード例 #16
0
        public override void Draw(LayoutElement element, Graphics graphics, LayoutProperties layoutProperties)
        {
            ImageElement imageElement = element as ImageElement;

            if (imageElement != null)
            {
                Point elementLocation = imageElement.Location.Multiply(layoutProperties.ZoomRatio);
                elementLocation = elementLocation.Add(layoutProperties.DesignAreaLocation);
                elementLocation = elementLocation.Subtract(layoutProperties.ViewportLocation);

                Size elementSize = imageElement.Size;
                elementSize = elementSize.Multiply(layoutProperties.ZoomRatio);

                graphics.DrawImage(imageElement.Image,
                                   new Rectangle(elementLocation, elementSize),
                                   new Rectangle(Point.Empty, imageElement.Image.Size),
                                   GraphicsUnit.Pixel);
            }
            else
            {
                throw new Exception("Cannot cast to ImageElement");
            }
        }
コード例 #17
0
        public LightTheme()
        {
            Palette = new CustomPalette
            {
                Primary               = Colors.Red.Default,
                PrimaryContrastText   = "#FFFFFF",
                Secondary             = Colors.Orange.Accent3,
                SecondaryContrastText = "#FFFFFF",
                AppbarBackground      = Colors.Red.Default,
                Tertiary              = Colors.BlueGrey.Default,

                Footer     = Colors.Red.Default,
                FooterDark = "#b9000a",
                FooterText = "#FFFFFF",

                Background = "#F1F1F1",
            };

            LayoutProperties = new LayoutProperties
            {
                DrawerWidthLeft = "260px"
            };
        }
コード例 #18
0
        public LayoutEditor(LayoutProperties prop, string layoutName, LayoutSide layoutSide)
        {
            instance = this;
            //LayoutProperties = prop;

            LayoutProperties.Name = LayoutProperties.Name;
            CurrentLayoutSide     = layoutSide;

            var m_piSize = MainWindow.CentimeterToPixel(prop.Size.X, prop.Size.Y);

            //m_LayoutLoader = new LayoutLoader();

            InitializeComponent();

            Canvas.SetLeft(ImageBackground, prop.Offset.X * MainWindow.DpiX / 2.54d / 100d);
            Canvas.SetTop(ImageBackground, prop.Offset.Y * MainWindow.DpiY / 2.54d / 100d);

            SetWindowSize((int)m_piSize.X, (int)m_piSize.Y, false);

            Task.Factory.StartNew(new Action(() =>
            {
                Dispatcher.Invoke(new MakeLayoutLoad(LoadLayout), new object[] { LayoutProperties });
            }));
        }
コード例 #19
0
        public Personalizacion()
        {
            Palette = new Palette()
            {
                Primary          = Colors.Blue.Darken1,
                Secondary        = Colors.DeepPurple.Accent2,
                Background       = Colors.Grey.Lighten5,
                AppbarBackground = Colors.Blue.Darken1,
                DrawerBackground = "#FFF",
                DrawerText       = "rgba(0,0,0, 0.7)",
                Success          = "#06d79c"
            };

            LayoutProperties = new LayoutProperties()
            {
                DefaultBorderRadius = "15px"
            };

            Typography = new Typography()
            {
                Default = new Default()
                {
                    FontFamily    = new[] { "Segoe UI", "Helvetica", "Arial", "sans-serif" },
                    FontSize      = ".875rem",
                    FontWeight    = 400,
                    LineHeight    = 1.43,
                    LetterSpacing = ".01071em"
                },
                H1 = new H1()
                {
                    FontFamily    = new[] { "Segoe UI", "Helvetica", "Arial", "sans-serif" },
                    FontSize      = "6rem",
                    FontWeight    = 300,
                    LineHeight    = 1.167,
                    LetterSpacing = "-.01562em"
                },
                H2 = new H2()
                {
                    FontFamily    = new[] { "Segoe UI", "Helvetica", "Arial", "sans-serif" },
                    FontSize      = "3.75rem",
                    FontWeight    = 300,
                    LineHeight    = 1.2,
                    LetterSpacing = "-.00833em"
                },
                H3 = new H3()
                {
                    FontFamily    = new[] { "Segoe UI", "Helvetica", "Arial", "sans-serif" },
                    FontSize      = "3rem",
                    FontWeight    = 400,
                    LineHeight    = 1.167,
                    LetterSpacing = "0"
                },
                H4 = new H4()
                {
                    FontFamily    = new[] { "Segoe UI", "Helvetica", "Arial", "sans-serif" },
                    FontSize      = "2.125rem",
                    FontWeight    = 400,
                    LineHeight    = 1.235,
                    LetterSpacing = ".00735em"
                },
                H5 = new H5()
                {
                    FontFamily    = new[] { "Segoe UI", "Helvetica", "Arial", "sans-serif" },
                    FontSize      = "1.5rem",
                    FontWeight    = 400,
                    LineHeight    = 1.334,
                    LetterSpacing = "0"
                },
                H6 = new H6()
                {
                    FontFamily    = new[] { "Segoe UI", "Helvetica", "Arial", "sans-serif" },
                    FontSize      = "1.25rem",
                    FontWeight    = 400,
                    LineHeight    = 1.6,
                    LetterSpacing = ".0075em"
                },
                Button = new Button()
                {
                    FontFamily    = new[] { "Segoe UI", "Helvetica", "Arial", "sans-serif" },
                    FontSize      = ".875rem",
                    FontWeight    = 500,
                    LineHeight    = 1.75,
                    LetterSpacing = ".02857em"
                },
                Body1 = new Body1()
                {
                    FontFamily    = new[] { "Segoe UI", "Helvetica", "Arial", "sans-serif" },
                    FontSize      = "1rem",
                    FontWeight    = 400,
                    LineHeight    = 1.5,
                    LetterSpacing = ".00938em"
                },
                Body2 = new Body2()
                {
                    FontFamily    = new[] { "Segoe UI", "Helvetica", "Arial", "sans-serif" },
                    FontSize      = ".875rem",
                    FontWeight    = 400,
                    LineHeight    = 1.43,
                    LetterSpacing = ".01071em"
                },
                Caption = new Caption()
                {
                    FontFamily    = new[] { "Segoe UI", "Helvetica", "Arial", "sans-serif" },
                    FontSize      = ".75rem",
                    FontWeight    = 400,
                    LineHeight    = 1.66,
                    LetterSpacing = ".03333em"
                },
                Subtitle2 = new Subtitle2()
                {
                    FontFamily    = new[] { "Segoe UI", "Helvetica", "Arial", "sans-serif" },
                    FontSize      = ".875rem",
                    FontWeight    = 500,
                    LineHeight    = 1.57,
                    LetterSpacing = ".00714em"
                }
            };
            Shadows = new Shadow();
            ZIndex  = new ZIndex();
        }
コード例 #20
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            controlMouseMoveLocation = e.Location;

            bool needsRefresh = false;

            LayoutProperties layoutProperties = new LayoutProperties();

            layoutProperties.DesignAreaLocation       = DesignAreaLocation;
            layoutProperties.DesignAreaSize           = DesignAreaSize;
            layoutProperties.ViewportLocation         = ViewportLocation;
            layoutProperties.ViewportSize             = ViewportSize;
            layoutProperties.ZoomRatio                = ZoomRatio;
            layoutProperties.ControlMouseDownLocation = controlMouseDownLocation;
            layoutProperties.ControlMouseMoveLocation = controlMouseMoveLocation;

            if (selectedElements != null)
            {
                foreach (LayoutElement selectedElement in selectedElements)
                {
                    TransformHandle handle = DesignerHelper.GetTransformHandleType(selectedElement, layoutProperties, controlMouseMoveLocation);
                    Cursor = DesignerHelper.GetCursorForTransformHandle(handle);
                }
            }

            if (isMouseDown)
            {
                // move
                if (interactionState == InteractionState.None && mouseHitsSelection && DesignerHelper.ExceedsThreshold(controlMouseMoveLocation, controlMouseDownLocation, MOVE_THRESHOLD))
                {
                    interactionState = InteractionState.Move;

                    // store offsets by mouse location
                    selectedElementOffsets = new List <Point>();
                    foreach (LayoutElement selectedElement in selectedElements)
                    {
                        Point selectedElementLocation = selectedElement.Location.Multiply(ZoomRatio);

                        selectedElementLocation = selectedElementLocation.Add(DesignAreaLocation);
                        selectedElementLocation = selectedElementLocation.Subtract(ViewportLocation);

                        selectedElementOffsets.Add(new Point(controlMouseMoveLocation.X - selectedElementLocation.X,
                                                             controlMouseMoveLocation.Y - selectedElementLocation.Y));
                    }
                }

                if (interactionState == InteractionState.SizeAttempt && DesignerHelper.ExceedsThreshold(controlMouseMoveLocation, controlMouseDownLocation, SIZE_THRESHOLD))
                {
                    interactionState    = InteractionState.Size;
                    interactionLocation = SelectedElement.Location;
                    interactionSize     = SelectedElement.Size;
                    needsRefresh        = true;
                }

                if (interactionState == InteractionState.Move)
                {
                    for (int i = 0; i < selectedElements.Count; i++)
                    {
                        LayoutElement selectedElement       = selectedElements[i];
                        Point         selectedElementOffset = selectedElementOffsets[i];

                        int selectedElementX = controlMouseMoveLocation.X + ViewportLocation.X - DesignAreaLocation.X;
                        selectedElementX -= selectedElementOffset.X;

                        int selectedElementY = controlMouseMoveLocation.Y + ViewportLocation.Y - DesignAreaLocation.Y;
                        selectedElementY -= selectedElementOffset.Y;

                        selectedElement.Location = new Point(selectedElementX, selectedElementY).Divide(ZoomRatio);
                    }

                    needsRefresh = true;
                }

                if (interactionState == InteractionState.Size)
                {
                    int locationX  = interactionLocation.X;
                    int locationY  = interactionLocation.Y;
                    int sizeWidth  = interactionSize.Width;
                    int sizeHeight = interactionSize.Height;

                    if (!KeyboardHelper.IsShiftKeyPressed)
                    {
                        if (transformHandle == TransformHandle.TopLeft)
                        {
                            locationX  = DesignAreaMouseMoveLocation.X;
                            locationY  = DesignAreaMouseMoveLocation.Y;
                            sizeWidth  = interactionLocation.X + interactionSize.Width - DesignAreaMouseMoveLocation.X;
                            sizeHeight = interactionLocation.Y + interactionSize.Height - DesignAreaMouseMoveLocation.Y;
                        }
                        else if (transformHandle == TransformHandle.TopCenter)
                        {
                            locationX  = interactionLocation.X;
                            locationY  = DesignAreaMouseMoveLocation.Y;
                            sizeWidth  = interactionSize.Width;
                            sizeHeight = interactionLocation.Y + interactionSize.Height - DesignAreaMouseMoveLocation.Y;
                        }
                        else if (transformHandle == TransformHandle.TopRight)
                        {
                            locationX  = interactionLocation.X;
                            locationY  = DesignAreaMouseMoveLocation.Y;
                            sizeWidth  = DesignAreaMouseMoveLocation.X - interactionLocation.X;
                            sizeHeight = interactionLocation.Y + interactionSize.Height - DesignAreaMouseMoveLocation.Y;
                        }
                        else if (transformHandle == TransformHandle.Left)
                        {
                            locationX  = DesignAreaMouseMoveLocation.X;
                            locationY  = interactionLocation.Y;
                            sizeWidth  = interactionLocation.X + interactionSize.Width - DesignAreaMouseMoveLocation.X;
                            sizeHeight = interactionSize.Height;
                        }
                        else if (transformHandle == TransformHandle.Right)
                        {
                            sizeWidth = DesignAreaMouseMoveLocation.X - interactionLocation.X;
                        }
                        else if (transformHandle == TransformHandle.BottomLeft)
                        {
                            locationX  = DesignAreaMouseMoveLocation.X;
                            locationY  = interactionLocation.Y;
                            sizeWidth  = interactionLocation.X + interactionSize.Width - DesignAreaMouseMoveLocation.X;
                            sizeHeight = DesignAreaMouseMoveLocation.Y - interactionLocation.Y;
                        }
                        else if (transformHandle == TransformHandle.BottomCenter)
                        {
                            sizeHeight = DesignAreaMouseMoveLocation.Y - interactionLocation.Y;
                        }
                        else if (transformHandle == TransformHandle.BottomRight)
                        {
                            sizeWidth  = DesignAreaMouseMoveLocation.X - interactionLocation.X;
                            sizeHeight = DesignAreaMouseMoveLocation.Y - interactionLocation.Y;
                        }
                    }
                    else
                    {
                        Point  pA;
                        Point  pK;
                        double m;
                        int    pPX;
                        int    pPY;

                        if (transformHandle == TransformHandle.TopLeft)
                        {
                            pA = new Point(interactionLocation.X + interactionSize.Width,
                                           interactionLocation.Y + interactionSize.Height);
                            pK = DesignAreaMouseMoveLocation;
                            m  = (double)interactionSize.Height / (double)interactionSize.Width;

                            pPX = (int)(((m * ((pA.X * m) - pA.Y + pK.Y)) + pK.X) / ((m * m) + 1));
                            pPY = (int)(((pPX - pA.X) * m) + pA.Y);

                            if (pA.X - pPX < SelectedElement.MinimumSize.Width)
                            {
                                locationX = pA.X - SelectedElement.MinimumSize.Width;
                            }
                            else
                            {
                                locationX = pPX;
                            }

                            if (pA.Y - pPY < SelectedElement.MinimumSize.Height)
                            {
                                locationY = pA.Y - SelectedElement.MinimumSize.Height;
                            }
                            else
                            {
                                locationY = pPY;
                            }

                            sizeWidth  = pA.X - pPX;
                            sizeHeight = pA.Y - pPY;
                        }
                        else if (transformHandle == TransformHandle.TopRight)
                        {
                            pA = new Point(interactionLocation.X,
                                           interactionLocation.Y + interactionSize.Height);
                            pK = DesignAreaMouseMoveLocation;
                            m  = -(double)interactionSize.Height / (double)interactionSize.Width;

                            pPX = (int)(((m * ((pA.X * m) - pA.Y + pK.Y)) + pK.X) / ((m * m) + 1));
                            pPY = (int)(((pPX - pA.X) * m) + pA.Y);

                            if (pA.Y - pPY < SelectedElement.MinimumSize.Height)
                            {
                                locationY = pA.Y - SelectedElement.MinimumSize.Height;
                            }
                            else
                            {
                                locationY = pPY;
                            }

                            sizeWidth  = pPX - pA.X;
                            sizeHeight = pA.Y - pPY;
                        }
                        else if (transformHandle == TransformHandle.BottomLeft)
                        {
                            pA = new Point(interactionLocation.X + interactionSize.Width,
                                           interactionLocation.Y);
                            pK = DesignAreaMouseMoveLocation;
                            m  = -(double)interactionSize.Height / (double)interactionSize.Width;

                            pPX = (int)(((m * ((pA.X * m) - pA.Y + pK.Y)) + pK.X) / ((m * m) + 1));
                            pPY = (int)(((pPX - pA.X) * m) + pA.Y);

                            if (pA.X - pPX < SelectedElement.MinimumSize.Width)
                            {
                                locationX = pA.X - SelectedElement.MinimumSize.Width;
                            }
                            else
                            {
                                locationX = pPX;
                            }

                            sizeWidth  = pA.X - pPX;
                            sizeHeight = pPY - pA.Y;
                        }
                        else if (transformHandle == TransformHandle.BottomRight)
                        {
                            pA = new Point(interactionLocation.X,
                                           interactionLocation.Y);
                            pK = DesignAreaMouseMoveLocation;
                            m  = (double)interactionSize.Height / (double)interactionSize.Width;

                            pPX = (int)(((m * ((pA.X * m) - pA.Y + pK.Y)) + pK.X) / ((m * m) + 1));
                            pPY = (int)(((pPX - pA.X) * m) + pA.Y);

                            sizeWidth  = pPX - pA.X;
                            sizeHeight = pPY - pA.Y;
                        }
                    }

                    if (locationX > interactionLocation.X + interactionSize.Width - SelectedElement.MinimumSize.Width)
                    {
                        locationX = interactionLocation.X + interactionSize.Width - SelectedElement.MinimumSize.Width;
                    }

                    if (locationY > interactionLocation.Y + interactionSize.Height - SelectedElement.MinimumSize.Height)
                    {
                        locationY = interactionLocation.Y + interactionSize.Height - SelectedElement.MinimumSize.Height;
                    }

                    if (locationX < interactionLocation.X + interactionSize.Width - SelectedElement.MaximumSize.Width)
                    {
                        locationX = interactionLocation.X + interactionSize.Width - SelectedElement.MaximumSize.Width;
                    }

                    if (locationY < interactionLocation.Y + interactionSize.Height - SelectedElement.MaximumSize.Height)
                    {
                        locationY = interactionLocation.Y + interactionSize.Height - SelectedElement.MaximumSize.Height;
                    }

                    if (sizeWidth < SelectedElement.MinimumSize.Width)
                    {
                        sizeWidth = SelectedElement.MinimumSize.Width;
                    }

                    if (sizeHeight < SelectedElement.MinimumSize.Height)
                    {
                        sizeHeight = SelectedElement.MinimumSize.Height;
                    }

                    if (sizeWidth > SelectedElement.MaximumSize.Width)
                    {
                        sizeWidth = SelectedElement.MaximumSize.Width;
                    }

                    if (sizeHeight > SelectedElement.MaximumSize.Height)
                    {
                        sizeHeight = SelectedElement.MaximumSize.Height;
                    }

                    SelectedElement.Location = new Point(locationX, locationY);
                    SelectedElement.Size     = new Size(sizeWidth, sizeHeight);

                    needsRefresh = true;
                }

                // selection
                if (interactionState == InteractionState.None && !mouseHitsSelection && DesignerHelper.ExceedsThreshold(controlMouseMoveLocation, controlMouseDownLocation, SELECTION_THRESHOLD))
                {
                    interactionState = InteractionState.Selection;
                    needsRefresh     = true;
                }

                if (interactionState == InteractionState.Selection)
                {
                    needsRefresh = true;
                }

                if (interactionState == InteractionState.Pan)
                {
                    ViewportLocation = oldViewportLocation.Subtract(controlMouseMoveLocation.Subtract(controlMouseDownLocation));
                    ValidateViewportLocation();

                    UpdateScrollBars();
                    needsRefresh = true;
                }
            }

            if (needsRefresh)
            {
                Refresh();
            }
        }
コード例 #21
0
        public void LoadLayout(LayoutProperties prop, StudentInfo student, List <string> disciplineLabels, bool isSkipEmplyLines = false, bool isAssessmentsOnLastLine = false)
        {
            using (new WaitCursor())
            {
                if (prop != null)
                {
                    var mediaOffset = prop.OffsetInPixel;

                    ClearLayout();

                    ImageBackground.Stretch = Stretch.Fill;
                    ImageBackground.Source  = LayoutFileReader.ByteToImageSource(prop.BackgroundImage);

                    Canvas.SetLeft(ImageBackground, mediaOffset.X);
                    Canvas.SetTop(ImageBackground, mediaOffset.Y);

                    // Add labels without data binding.
                    foreach (var ci in prop.m_CaptionInfo.Where(t => Helper.IsNoneBinding(t.XlsColumn)).AsParallel())
                    {
                        AddSpanElement(ci.CaptionText, ci, mediaOffset);
                    }

                    // Add labels with data binding.
                    foreach (var column in XLSColumnBinding.GetXLSColums(prop.LayoutType).AsParallel())
                    {
                        if (Helper.IsNoneBinding(column))
                        {
                            continue;
                        }

                        foreach (var caption in prop.m_CaptionInfo.Where(t => t.XlsColumn == column))
                        {
                            AddSpanElement(student.GetValue(column), caption, mediaOffset);
                        }
                    }



                    // Add tables.
                    var m_TableDataSet = new TableDataSet(disciplineLabels, student.Assessments, isSkipEmplyLines, isAssessmentsOnLastLine);
                    var seek           = 0;

                    foreach (var tbl in prop.m_Table.OrderBy(t => t.Left + t.Top).AsParallel())
                    {
                        AddTableElement(tbl, m_TableDataSet.Range(seek, tbl.RowCount), mediaOffset);
                        seek += tbl.RowCount;
                    }

                    //foreach (var tbl in prop.m_Table.Where(t => t.XlsColumn == "Оценки слева").OrderBy(t => t.Top).AsParallel())
                    //    seek = AddTableElement(tbl, m_TableDataSet, seek, mediaOffset);
                    //foreach (var tbl in prop.m_Table.Where(t => t.XlsColumn == "Оценки справа").OrderBy(t => t.Top).AsParallel())
                    //    seek = AddTableElement(tbl, m_TableDataSet, seek, mediaOffset);

                    // Add guide lines.
                    foreach (var ci in prop.m_GuideLineInfo)
                    {
                        AddGuigeLine(ci, mediaOffset);
                    }
                    // Add sumbols.
                    foreach (var ci in prop.m_ZSumbolInfo)
                    {
                        AddZSumbolElement(ci, mediaOffset);
                    }
                }
            }
        }
コード例 #22
0
        public static void DrawTransformHandles(Graphics graphics, LayoutElement element, LayoutProperties layoutProperties, TransformHandleType handleType)
        {
            Point elementLocation = element.Location.Multiply(layoutProperties.ZoomRatio);

            elementLocation = elementLocation.Add(layoutProperties.DesignAreaLocation);
            elementLocation = elementLocation.Subtract(layoutProperties.ViewportLocation);

            Size elementSize = element.Size;

            elementSize = elementSize.Multiply(layoutProperties.ZoomRatio);

            Pen penRectangle = new Pen(Color.Silver);

            graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation, elementSize), 1);

            Pen   penHandle   = new Pen(Color.Black);
            Brush brushHandle = new SolidBrush(Color.White);

            Size handleSize = new Size(HANDLE_WIDTH, HANDLE_HEIGHT);

            if (handleType == TransformHandleType.All || handleType == TransformHandleType.OnlyCorners)
            {
                graphics.FillRoundedRectangle(brushHandle, new Rectangle(elementLocation.Subtract(handleSize.Half()), handleSize), 2);
                graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation.Subtract(handleSize.Half()), handleSize), 2);
            }

            if (handleType == TransformHandleType.All)
            {
                graphics.FillRoundedRectangle(brushHandle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width / 2), handleSize), 2);
                graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width / 2), handleSize), 2);
            }

            if (handleType == TransformHandleType.All || handleType == TransformHandleType.OnlyCorners)
            {
                graphics.FillRoundedRectangle(brushHandle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width), handleSize), 2);
                graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width), handleSize), 2);
            }

            if (handleType == TransformHandleType.All)
            {
                graphics.FillRoundedRectangle(brushHandle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddY(elementSize.Height / 2), handleSize), 2);
                graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddY(elementSize.Height / 2), handleSize), 2);
            }

            if (handleType == TransformHandleType.All)
            {
                graphics.FillRoundedRectangle(brushHandle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width).AddY(elementSize.Height / 2), handleSize), 2);
                graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width).AddY(elementSize.Height / 2), handleSize), 2);
            }

            if (handleType == TransformHandleType.All || handleType == TransformHandleType.OnlyCorners)
            {
                graphics.FillRoundedRectangle(brushHandle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddY(elementSize.Height), handleSize), 2);
                graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddY(elementSize.Height), handleSize), 2);
            }

            if (handleType == TransformHandleType.All)
            {
                graphics.FillRoundedRectangle(brushHandle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width / 2).AddY(elementSize.Height), handleSize), 2);
                graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width / 2).AddY(elementSize.Height), handleSize), 2);
            }

            if (handleType == TransformHandleType.All || handleType == TransformHandleType.OnlyCorners)
            {
                graphics.FillRoundedRectangle(brushHandle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width).AddY(elementSize.Height), handleSize), 2);
                graphics.DrawRoundedRectangle(penRectangle, new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width).AddY(elementSize.Height), handleSize), 2);
            }
        }
コード例 #23
0
        public static TransformHandle GetTransformHandleType(LayoutElement element, LayoutProperties layoutProperties, Point location)
        {
            Point elementLocation = element.Location.Multiply(layoutProperties.ZoomRatio);

            elementLocation = elementLocation.Add(layoutProperties.DesignAreaLocation);
            elementLocation = elementLocation.Subtract(layoutProperties.ViewportLocation);

            Size elementSize = element.Size;

            elementSize = elementSize.Multiply(layoutProperties.ZoomRatio);

            Size handleSize = new Size(HANDLE_WIDTH, HANDLE_HEIGHT);

            Rectangle rectangle = new Rectangle(elementLocation.Subtract(handleSize.Half()), handleSize);

            if (rectangle.Contains(location))
            {
                return(TransformHandle.TopLeft);
            }

            rectangle = new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width / 2), handleSize);
            if (rectangle.Contains(location))
            {
                return(TransformHandle.TopCenter);
            }

            rectangle = new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width), handleSize);
            if (rectangle.Contains(location))
            {
                return(TransformHandle.TopRight);
            }

            rectangle = new Rectangle(elementLocation.Subtract(handleSize.Half()).AddY(elementSize.Height / 2), handleSize);
            if (rectangle.Contains(location))
            {
                return(TransformHandle.Left);
            }

            rectangle = new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width).AddY(elementSize.Height / 2), handleSize);
            if (rectangle.Contains(location))
            {
                return(TransformHandle.Right);
            }

            rectangle = new Rectangle(elementLocation.Subtract(handleSize.Half()).AddY(elementSize.Height), handleSize);
            if (rectangle.Contains(location))
            {
                return(TransformHandle.BottomLeft);
            }

            rectangle = new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width / 2).AddY(elementSize.Height), handleSize);
            if (rectangle.Contains(location))
            {
                return(TransformHandle.BottomCenter);
            }

            rectangle = new Rectangle(elementLocation.Subtract(handleSize.Half()).AddX(elementSize.Width).AddY(elementSize.Height), handleSize);
            if (rectangle.Contains(location))
            {
                return(TransformHandle.BottomRight);
            }

            return(TransformHandle.None);
        }
コード例 #24
0
ファイル: Layout.cs プロジェクト: cdiggins/widgetology
 public static Layout CreateHorizontal(LayoutProperties props, params IControl[] children)
 => new(LayoutHelpers.SplitHorizontally, props, null, children);
コード例 #25
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            controlMouseDownLocation = e.Location;

            isMouseDown = true;

            bool needsRefresh = false;

            mouseHitsSelection = false;

            if (e.Button == MouseButtons.Left)
            {
                // resize
                if (interactionState == InteractionState.None && selectedElements != null && selectedElements.Count == 1)
                {
                    LayoutProperties layoutProperties = new LayoutProperties();
                    layoutProperties.DesignAreaLocation = DesignAreaLocation;
                    layoutProperties.DesignAreaSize     = DesignAreaSize;
                    layoutProperties.ViewportLocation   = ViewportLocation;
                    layoutProperties.ViewportSize       = ViewportSize;
                    layoutProperties.ZoomRatio          = ZoomRatio;

                    foreach (LayoutElement selectedElement in selectedElements)
                    {
                        TransformHandle transformHandle = DesignerHelper.GetTransformHandleType(selectedElement, layoutProperties, e.Location);
                        if (transformHandle != TransformHandle.None)
                        {
                            this.transformHandle = transformHandle;
                            interactionState     = InteractionState.SizeAttempt;
                            needsRefresh         = true;
                        }
                    }
                }

                // click selection
                if (interactionState == InteractionState.None)
                {
                    LayoutElement element = GetElementByLocation(controlMouseDownLocation);
                    if (element != null)
                    {
                        mouseHitsSelection = true;

                        if (KeyboardHelper.IsShiftKeyPressed)
                        {
                            if (!IsElementInSelection(element))
                            {
                                AddElementToSelection(element);
                            }
                            else
                            {
                                RemoveElementFromSelection(element);
                            }
                        }
                        else
                        {
                            if (!IsElementInSelection(element))
                            {
                                ClearSelection();
                                AddElementToSelection(element);
                            }
                        }

                        needsRefresh = true;
                    }
                    else
                    {
                        if (!KeyboardHelper.IsShiftKeyPressed)
                        {
                            ClearSelection();
                            needsRefresh = true;
                        }
                    }
                }
            }

            if (e.Button == MouseButtons.Middle || interactionState == InteractionState.Pan)
            {
                interactionState = InteractionState.Pan;

                if (panSource == PanSource.None)
                {
                    panSource = PanSource.Mouse;
                }

                oldViewportLocation = ViewportLocation;

                Cursor = CursorHelper.LoadFromResource(Properties.Resources.grabbing);

                needsRefresh = true;
            }

            if (needsRefresh)
            {
                Refresh();
            }
        }